Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,15 +4,19 @@ from huggingface_hub import InferenceClient
|
|
| 4 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta") #change LLM
|
| 5 |
|
| 6 |
def respond(message, history):
|
| 7 |
-
messages = [{"role": "system", "content": "You are a friendly chatbot."}]
|
| 8 |
if history:
|
| 9 |
messages.extend(history)
|
| 10 |
-
messages.append({"role": "user", "content":
|
| 11 |
-
response =
|
|
|
|
| 12 |
messages,
|
| 13 |
-
max_tokens=100
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
chatbot = gr.ChatInterface(respond, type="messages")
|
| 18 |
|
|
|
|
| 4 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta") #change LLM
|
| 5 |
|
| 6 |
def respond(message, history):
|
| 7 |
+
messages = [{"role": "system", "content": "You are a friendly chatbot."}]
|
| 8 |
if history:
|
| 9 |
messages.extend(history)
|
| 10 |
+
messages.append({"role": "user", "content": message})
|
| 11 |
+
response = ""
|
| 12 |
+
for message in client.chat_completion(
|
| 13 |
messages,
|
| 14 |
+
max_tokens=100,
|
| 15 |
+
stream=True,
|
| 16 |
+
):
|
| 17 |
+
token = messages.choices[0].delta.content
|
| 18 |
+
response += token
|
| 19 |
+
yield response
|
| 20 |
|
| 21 |
chatbot = gr.ChatInterface(respond, type="messages")
|
| 22 |
|