Add error logging to chat stream

main
Clawd 3 weeks ago
parent acbab75031
commit 7731595022

@ -60,6 +60,8 @@ Answer based on the above context:"""
],
}
logger.info(f"Chat request to {url} with model {model}")
# Yield sources first
sources = [
{'title': c.title, 'path': c.path, 'score': c.score}
@ -68,8 +70,10 @@ Answer based on the above context:"""
yield f'data: {json.dumps({"type": "sources", "sources": sources})}\n\n'
# Stream tokens
async with httpx.AsyncClient(timeout=120.0) as client:
try:
async with httpx.AsyncClient(timeout=180.0) as client:
async with client.stream('POST', url, json=payload) as resp:
logger.info(f"Ollama response status: {resp.status_code}")
resp.raise_for_status()
async for line in resp.aiter_lines():
if not line.strip():
@ -83,5 +87,8 @@ Answer based on the above context:"""
break
except json.JSONDecodeError:
continue
except Exception as e:
logger.error(f"Chat stream error: {e}")
yield f'data: {json.dumps({"type": "error", "error": str(e)})}\n\n'
yield f'data: {json.dumps({"type": "done"})}\n\n'

Loading…
Cancel
Save

Powered by TurnKey Linux.