Update app.py
Browse files
app.py
CHANGED
@@ -32,7 +32,7 @@ async def respond(
|
|
32 |
messages.append({"role": "user", "content": message})
|
33 |
|
34 |
response = ""
|
35 |
-
#
|
36 |
stream = client.chat.completions.create(
|
37 |
model="NousResearch/Hermes-3-Llama-3.1-8B",
|
38 |
max_tokens=max_tokens,
|
@@ -41,9 +41,10 @@ async def respond(
|
|
41 |
top_p=top_p,
|
42 |
messages=messages,
|
43 |
)
|
44 |
-
for
|
45 |
-
|
46 |
-
|
|
|
47 |
return response
|
48 |
except APIError as e:
|
49 |
error_details = e.body
|
|
|
32 |
messages.append({"role": "user", "content": message})
|
33 |
|
34 |
response = ""
|
35 |
+
# Properly stream chat completions using dot notation
|
36 |
stream = client.chat.completions.create(
|
37 |
model="NousResearch/Hermes-3-Llama-3.1-8B",
|
38 |
max_tokens=max_tokens,
|
|
|
41 |
top_p=top_p,
|
42 |
messages=messages,
|
43 |
)
|
44 |
+
for chunk in stream: # Iterate over the streamed response chunks
|
45 |
+
if hasattr(chunk.choices[0].delta, 'content'):
|
46 |
+
token = chunk.choices[0].delta.content
|
47 |
+
response += token
|
48 |
return response
|
49 |
except APIError as e:
|
50 |
error_details = e.body
|