Spaces:
Sleeping
Sleeping
richardkovacs
commited on
Commit
•
24c5da9
1
Parent(s):
eac00b8
feat: handle errors more gracefully
Browse files
app.py
CHANGED
@@ -35,19 +35,25 @@ def respond(
|
|
35 |
|
36 |
response = ""
|
37 |
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
|
|
46 |
|
47 |
-
|
48 |
-
|
49 |
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
"""
|
53 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
|
|
35 |
|
36 |
response = ""
|
37 |
|
38 |
+
try:
|
39 |
+
for message in client.chat_completion(
|
40 |
+
messages,
|
41 |
+
max_tokens=max_tokens,
|
42 |
+
stream=True,
|
43 |
+
temperature=temperature,
|
44 |
+
top_p=top_p,
|
45 |
+
):
|
46 |
+
token = message.choices[0].delta.content
|
47 |
|
48 |
+
if token:
|
49 |
+
response += token
|
50 |
|
51 |
+
yield response
|
52 |
+
except ValueError as e:
|
53 |
+
print("ERROR:", e)
|
54 |
+
raise gr.Error("We have some trouble connecting to the model. Please try again later.")
|
55 |
+
except Exception as e:
|
56 |
+
raise gr.Error("An unknown error occurred. Please try again later.")
|
57 |
|
58 |
"""
|
59 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|