Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -27,29 +27,29 @@ def respond(
|
|
27 |
|
28 |
response = ""
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
print(f"Error processing message: {e}")
|
49 |
-
continue
|
50 |
-
except Exception as e:
|
51 |
-
print(f"Unexpected error: {e}")
|
52 |
-
yield "An error occurred while generating the response."
|
53 |
|
54 |
"""
|
55 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
|
|
27 |
|
28 |
response = ""
|
29 |
|
30 |
+
|
31 |
+
for message in client.chat_completion(
|
32 |
+
messages,
|
33 |
+
max_tokens=max_tokens,
|
34 |
+
stream=True,
|
35 |
+
temperature=temperature,
|
36 |
+
top_p=top_p,
|
37 |
+
):
|
38 |
+
print("MESSAGE", message)
|
39 |
+
# Check if the message is in the expected format
|
40 |
+
if not message or not isinstance(message, dict):
|
41 |
+
continue
|
42 |
+
|
43 |
+
# Extract token and handle potential errors in parsing
|
44 |
+
try:
|
45 |
+
token = message.choices[0].delta.content
|
46 |
|
47 |
+
response += token
|
48 |
+
yield response
|
49 |
+
except (AttributeError, IndexError, KeyError) as e:
|
50 |
+
print(f"Error processing message: {e}")
|
51 |
+
continue
|
52 |
+
|
|
|
|
|
|
|
|
|
|
|
53 |
|
54 |
"""
|
55 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|