chansung commited on
Commit
135d31c
1 Parent(s): 0d8015c

Update app/main.py

Browse files
Files changed (1) hide show
  1. app/main.py +10 -8
app/main.py CHANGED
@@ -1,9 +1,8 @@
1
  import gradio as gr
2
- from text_generation import AsyncClient
3
- import text_generation.types.Message as Message
4
 
5
- endpoint_url = "http://127.0.0.1:8080"
6
- client = AsyncClient(endpoint_url)
7
 
8
  """
9
  frequency_penalty: Optional[float] = None,
@@ -32,18 +31,21 @@ def _translate_messages(history):
32
  messages = []
33
 
34
  for conv in history:
35
- messages.append(Message(role="user", content=conv[0]))
36
- messages.append(Message(role="assistant", content=conv[1]))
37
 
38
  return messages
39
 
40
  async def echo(message, history):
41
  parameters = _default_parameters()
42
  messages = _translate_messages(history)
 
43
 
44
  history.append([message, ""])
45
- full_resp = ""
46
- async for resp in client.chat(messages=messages, **parameters):
 
 
47
  full_resp = full_resp + resp.choices[0].delta.content
48
  history[-1][1] = full_resp
49
  yield history
 
1
  import gradio as gr
2
+ from openai import AsyncOpenAI
 
3
 
4
+ base_url = "http://127.0.0.1:8080/v1"
5
+ client = AsyncOpenAI(base_url=base_url, api_key="-")
6
 
7
  """
8
  frequency_penalty: Optional[float] = None,
 
31
  messages = []
32
 
33
  for conv in history:
34
+ messages.append({"role":"user", "content":conv[0]))
35
+ messages.append({"role":"assistant", "content":conv[1]))
36
 
37
  return messages
38
 
39
  async def echo(message, history):
40
  parameters = _default_parameters()
41
  messages = _translate_messages(history)
42
+ messages.append()
43
 
44
  history.append([message, ""])
45
+ full_resp = ""
46
+ async for resp in client.chat.completions.create(
47
+ model="tgi", messages=messages, **parameters
48
+ ):
49
  full_resp = full_resp + resp.choices[0].delta.content
50
  history[-1][1] = full_resp
51
  yield history