Update app.py
Browse files
app.py
CHANGED
@@ -30,20 +30,14 @@ def respond(
|
|
30 |
|
31 |
messages.append({"role": "user", "content": message})
|
32 |
|
33 |
-
response =
|
34 |
-
|
35 |
-
for message in client.chat.completions.create(
|
36 |
model="NousResearch/Hermes-3-Llama-3.1-8B",
|
37 |
max_tokens=max_tokens,
|
38 |
-
stream=True,
|
39 |
temperature=temperature,
|
40 |
top_p=top_p,
|
41 |
messages=messages,
|
42 |
-
)
|
43 |
-
|
44 |
-
|
45 |
-
response += token
|
46 |
-
yield response
|
47 |
except APIError as e:
|
48 |
error_details = e.body
|
49 |
error_type = error_details.get("type")
|
@@ -57,10 +51,10 @@ def respond(
|
|
57 |
error_str = "An error occurred during streaming"
|
58 |
|
59 |
print(f"Error: {error_str}")
|
60 |
-
|
61 |
except Exception as e:
|
62 |
print(f"Error: {e}")
|
63 |
-
|
64 |
|
65 |
def launch_app():
|
66 |
try:
|
|
|
30 |
|
31 |
messages.append({"role": "user", "content": message})
|
32 |
|
33 |
+
response = client.chat.completions.create(
|
|
|
|
|
34 |
model="NousResearch/Hermes-3-Llama-3.1-8B",
|
35 |
max_tokens=max_tokens,
|
|
|
36 |
temperature=temperature,
|
37 |
top_p=top_p,
|
38 |
messages=messages,
|
39 |
+
)
|
40 |
+
return response.choices[0].delta.content
|
|
|
|
|
|
|
41 |
except APIError as e:
|
42 |
error_details = e.body
|
43 |
error_type = error_details.get("type")
|
|
|
51 |
error_str = "An error occurred during streaming"
|
52 |
|
53 |
print(f"Error: {error_str}")
|
54 |
+
return error_str
|
55 |
except Exception as e:
|
56 |
print(f"Error: {e}")
|
57 |
+
return "Error occurred. Please try again."
|
58 |
|
59 |
def launch_app():
|
60 |
try:
|