Spaces:
Running
Running
Another update
Browse files
app.py
CHANGED
|
@@ -15,29 +15,41 @@ def respond(
|
|
| 15 |
temperature,
|
| 16 |
top_p,
|
| 17 |
):
|
| 18 |
-
messages = [{"role": "system", "content": system_message}]
|
|
|
|
| 19 |
|
| 20 |
-
|
| 21 |
-
if val[0]:
|
| 22 |
-
messages.append({"role": "user", "content": val[0]})
|
| 23 |
-
if val[1]:
|
| 24 |
-
messages.append({"role": "assistant", "content": val[1]})
|
| 25 |
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
messages,
|
| 32 |
-
max_tokens=max_tokens,
|
| 33 |
-
stream=True,
|
| 34 |
-
temperature=temperature,
|
| 35 |
-
top_p=top_p,
|
| 36 |
):
|
| 37 |
-
token =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
| 41 |
|
| 42 |
|
| 43 |
"""
|
|
@@ -62,7 +74,7 @@ For information on how to customize the ChatInterface, peruse the gradio docs: h
|
|
| 62 |
with gr.Blocks() as demo:
|
| 63 |
gr.Markdown("## Zephyr Chatbot with Custom UI")
|
| 64 |
|
| 65 |
-
chatbot = gr.Chatbot()
|
| 66 |
state = gr.State([])
|
| 67 |
|
| 68 |
with gr.Row():
|
|
|
|
| 15 |
temperature,
|
| 16 |
top_p,
|
| 17 |
):
|
| 18 |
+
messages = [{"role": "system", "content": system_message}] + history
|
| 19 |
+
messages.append({"role":"user","content":message})
|
| 20 |
|
| 21 |
+
reponse = ""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
# for val in history:
|
| 24 |
+
# if val[0]:
|
| 25 |
+
# messages.append({"role": "user", "content": val[0]})
|
| 26 |
+
# if val[1]:
|
| 27 |
+
# messages.append({"role": "assistant", "content": val[1]})
|
| 28 |
|
| 29 |
+
for part in client.chat_completion(
|
| 30 |
+
messages, max_tokens=max_tokens, streams=True, temperature=temperature,
|
| 31 |
+
top_p=top_p
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
):
|
| 33 |
+
token = part.choices[0].delta.content
|
| 34 |
+
if token:
|
| 35 |
+
response += token
|
| 36 |
+
|
| 37 |
+
history.append({"role":"user", "content": message})
|
| 38 |
+
history.append({"role":"assistant", "content": respond})
|
| 39 |
+
|
| 40 |
+
return history,""
|
| 41 |
+
|
| 42 |
+
# for message in client.chat_completion(
|
| 43 |
+
# messages,
|
| 44 |
+
# max_tokens=max_tokens,
|
| 45 |
+
# stream=True,
|
| 46 |
+
# temperature=temperature,
|
| 47 |
+
# top_p=top_p,
|
| 48 |
+
# ):
|
| 49 |
+
# token = message.choices[0].delta.content
|
| 50 |
|
| 51 |
+
# response += token
|
| 52 |
+
# yield response
|
| 53 |
|
| 54 |
|
| 55 |
"""
|
|
|
|
| 74 |
with gr.Blocks() as demo:
|
| 75 |
gr.Markdown("## Zephyr Chatbot with Custom UI")
|
| 76 |
|
| 77 |
+
chatbot = gr.Chatbot(type="messages", label="Chatbot")
|
| 78 |
state = gr.State([])
|
| 79 |
|
| 80 |
with gr.Row():
|