Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -25,8 +25,9 @@ def respond(
|
|
25 |
|
26 |
messages.append({"role": "user", "content": message})
|
27 |
|
28 |
-
|
29 |
|
|
|
30 |
for message in client.chat_completion(
|
31 |
messages,
|
32 |
max_tokens=max_tokens,
|
@@ -34,11 +35,25 @@ def respond(
|
|
34 |
temperature=temperature,
|
35 |
top_p=top_p,
|
36 |
):
|
|
|
|
|
|
|
|
|
37 |
token = message.choices[0].delta.content
|
38 |
|
39 |
response += token
|
40 |
yield response
|
41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
"""
|
44 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
|
|
25 |
|
26 |
messages.append({"role": "user", "content": message})
|
27 |
|
28 |
+
response = ""
|
29 |
|
30 |
+
try:
|
31 |
for message in client.chat_completion(
|
32 |
messages,
|
33 |
max_tokens=max_tokens,
|
|
|
35 |
temperature=temperature,
|
36 |
top_p=top_p,
|
37 |
):
|
38 |
+
# Verifica se a resposta contém o conteúdo esperado
|
39 |
+
if 'choices' not in message or len(message.choices) == 0 or 'delta' not in message.choices[0]:
|
40 |
+
raise ValueError("Resposta inesperada do modelo.")
|
41 |
+
|
42 |
token = message.choices[0].delta.content
|
43 |
|
44 |
response += token
|
45 |
yield response
|
46 |
|
47 |
+
except ValueError as e:
|
48 |
+
print(f"Erro de valor: {e}")
|
49 |
+
except ConnectionError as e:
|
50 |
+
print(f"Erro de conexão: {e}")
|
51 |
+
except TimeoutError as e:
|
52 |
+
print(f"Erro de tempo: {e}")
|
53 |
+
except Exception as e:
|
54 |
+
print(f"Erro inesperado: {e}")
|
55 |
+
|
56 |
+
|
57 |
|
58 |
"""
|
59 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|