Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -19,16 +19,21 @@ def respond(message, history, system_message, max_tokens, temperature, top_p):
|
|
19 |
messages.append({"role": "user", "content": message})
|
20 |
|
21 |
response = ""
|
22 |
-
for
|
23 |
messages,
|
24 |
max_tokens=max_tokens,
|
25 |
stream=True,
|
26 |
temperature=temperature,
|
27 |
top_p=top_p,
|
28 |
):
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
def clear_session():
|
34 |
return "", []
|
|
|
19 |
messages.append({"role": "user", "content": message})
|
20 |
|
21 |
response = ""
|
22 |
+
for chunk in client.chat_completion(
|
23 |
messages,
|
24 |
max_tokens=max_tokens,
|
25 |
stream=True,
|
26 |
temperature=temperature,
|
27 |
top_p=top_p,
|
28 |
):
|
29 |
+
if chunk.choices[0].delta.content is not None:
|
30 |
+
token = chunk.choices[0].delta.content
|
31 |
+
response += token
|
32 |
+
yield history + [(message, response)]
|
33 |
+
|
34 |
+
# If the response is empty, yield a default message
|
35 |
+
if not response:
|
36 |
+
yield history + [(message, "I apologize, but I couldn't generate a response.")]
|
37 |
|
38 |
def clear_session():
|
39 |
return "", []
|