Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -440,9 +440,14 @@ def chat():
|
|
| 440 |
if response.status_code == 200:
|
| 441 |
for line in response.iter_lines():
|
| 442 |
if line:
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 446 |
return
|
| 447 |
except Exception as colab_err:
|
| 448 |
logger.warning(f"Colab streaming failed: {colab_err}. Switching to HF...")
|
|
|
|
| 440 |
if response.status_code == 200:
|
| 441 |
for line in response.iter_lines():
|
| 442 |
if line:
|
| 443 |
+
try:
|
| 444 |
+
chunk = json.loads(line)
|
| 445 |
+
if 'message' in chunk and 'content' in chunk['message']:
|
| 446 |
+
token = chunk['message']['content']
|
| 447 |
+
yield json.dumps({"token": token, "source": "colab", "provider": "Nexa AI (Colab)", "tools_used": tools_needed}) + "\n"
|
| 448 |
+
except Exception as e:
|
| 449 |
+
logger.error(f"Error parsing Ollama chunk: {e}")
|
| 450 |
+
continue
|
| 451 |
return
|
| 452 |
except Exception as colab_err:
|
| 453 |
logger.warning(f"Colab streaming failed: {colab_err}. Switching to HF...")
|