Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -20,28 +20,29 @@ def respond(
|
|
20 |
top_p,
|
21 |
):
|
22 |
messages = [{"role": "system", "content": system_message}]
|
23 |
-
|
24 |
for val in history:
|
25 |
if val[0]:
|
26 |
messages.append({"role": "user", "content": val[0]})
|
27 |
if val[1]:
|
28 |
messages.append({"role": "assistant", "content": val[1]})
|
29 |
-
|
30 |
messages.append({"role": "user", "content": message})
|
31 |
|
32 |
response = ""
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
|
|
|
|
|
|
45 |
|
46 |
|
47 |
demo = gr.ChatInterface(
|
|
|
20 |
top_p,
|
21 |
):
|
22 |
messages = [{"role": "system", "content": system_message}]
|
|
|
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 |
messages.append({"role": "user", "content": message})
|
29 |
|
30 |
response = ""
|
31 |
+
try:
|
32 |
+
response_stream = client.chat_completion(
|
33 |
+
messages,
|
34 |
+
max_tokens=max_tokens,
|
35 |
+
stream=True,
|
36 |
+
temperature=temperature,
|
37 |
+
top_p=top_p,
|
38 |
+
)
|
39 |
+
for message in response_stream:
|
40 |
+
token = message.choices[0].delta.content
|
41 |
+
response += token
|
42 |
+
yield response
|
43 |
+
except (json.JSONDecodeError, ValueError) as e:
|
44 |
+
print(f"Error decoding response: {e}")
|
45 |
+
yield "An error occurred while processing the request."
|
46 |
|
47 |
|
48 |
demo = gr.ChatInterface(
|