umar8902 commited on
Commit
9b24ae2
·
verified ·
1 Parent(s): 822796e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -3
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
- chunk = json.loads(line)
444
- if 'message' in chunk and 'content' in chunk['message']:
445
- yield json.dumps({"token": chunk['message']['content'], "source": "colab", "provider": "Ollama (Phi-3)", "tools_used": tools_needed}) + "\n"
 
 
 
 
 
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...")