Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -53,28 +53,28 @@ def stream_completion(message: str,
|
|
| 53 |
# Current user input comes last
|
| 54 |
messages.append({"role": "user", "content": message})
|
| 55 |
|
| 56 |
-
try:
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
except Exception as err: # pylint: disable=broad-except
|
| 77 |
-
|
| 78 |
|
| 79 |
|
| 80 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
|
|
| 53 |
# Current user input comes last
|
| 54 |
messages.append({"role": "user", "content": message})
|
| 55 |
|
| 56 |
+
#try:
|
| 57 |
+
# Kick off streaming completion
|
| 58 |
+
response = openai.chat.completions.create(
|
| 59 |
+
model="Qwen/Qwen3-4B",
|
| 60 |
+
messages=messages,
|
| 61 |
+
temperature=temperature,
|
| 62 |
+
top_p=top_p,
|
| 63 |
+
max_tokens=max_tokens,
|
| 64 |
+
stream=True,
|
| 65 |
+
# Forward MoI blending coefficient to the backend
|
| 66 |
+
extra_headers={"X-MIXINPUTS-BETA": str(beta)},
|
| 67 |
+
)
|
| 68 |
+
|
| 69 |
+
assistant = ""
|
| 70 |
+
for chunk in response:
|
| 71 |
+
# ``delta.content`` is None for e.g. role announcements; guard with or ""
|
| 72 |
+
delta = chunk.choices[0].delta.content or ""
|
| 73 |
+
assistant += delta
|
| 74 |
+
yield history + [(message, assistant)] # live update
|
| 75 |
+
|
| 76 |
+
# except Exception as err: # pylint: disable=broad-except
|
| 77 |
+
# yield history + [(message, f"[ERROR] {err}")]
|
| 78 |
|
| 79 |
|
| 80 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|