Spaces:
Sleeping
Sleeping
inteligenciamilgrau
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -31,47 +31,15 @@ def respond(
|
|
31 |
response = ""
|
32 |
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
if not message or not isinstance(message, dict):
|
44 |
-
continue
|
45 |
-
|
46 |
-
try:
|
47 |
-
# Extract content and finish reason
|
48 |
-
content = message.choices[0].delta.content
|
49 |
-
finish_reason = message.choices[0].finish_reason
|
50 |
-
|
51 |
-
# Check if the content is empty
|
52 |
-
if content.strip() == "":
|
53 |
-
# If the finish reason is 'stop', it's expected and we can break the loop
|
54 |
-
if finish_reason == "stop":
|
55 |
-
print("Stream ended normally.")
|
56 |
-
break
|
57 |
-
else:
|
58 |
-
print("Received unexpected empty content, skipping...")
|
59 |
-
continue
|
60 |
-
|
61 |
-
response += content
|
62 |
-
yield response
|
63 |
-
|
64 |
-
except (AttributeError, IndexError, KeyError) as e:
|
65 |
-
print(f"Error processing message: {e}")
|
66 |
-
continue
|
67 |
-
|
68 |
-
except Exception as e:
|
69 |
-
print(f"Unexpected error: {e}")
|
70 |
-
yield "An error occurred while generating the response."
|
71 |
-
|
72 |
-
# Final check if the response is empty
|
73 |
-
if response.strip() == "":
|
74 |
-
yield "No response generated. Please try again or adjust the settings."
|
75 |
|
76 |
|
77 |
"""
|
|
|
31 |
response = ""
|
32 |
|
33 |
|
34 |
+
mensagens = client.chat_completion(
|
35 |
+
messages,
|
36 |
+
max_tokens=max_tokens,
|
37 |
+
temperature=temperature,
|
38 |
+
top_p=top_p,
|
39 |
+
)
|
40 |
+
response = mensagens.choices[0].message.content
|
41 |
+
|
42 |
+
return response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
|
45 |
"""
|