forked from Rockachopa/Timmy-time-dashboard
fix: log Ollama disconnections with specific error handling (#92)
- BaseAgent.run(): catch httpx.ConnectError/ReadError/ConnectionError, log 'Ollama disconnected: <error>' at ERROR level, then re-raise - session.py: distinguish Ollama disconnects from other errors in chat(), chat_with_tools(), continue_chat() — return specific message 'Ollama appears to be disconnected' instead of generic error - 11 new tests covering all disconnect paths
This commit is contained in:
@@ -11,6 +11,8 @@ let Agno's session_id mechanism handle conversation continuity.
|
||||
import logging
|
||||
import re
|
||||
|
||||
import httpx
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Default session ID for the dashboard (stable across requests)
|
||||
@@ -83,6 +85,9 @@ async def chat(message: str, session_id: str | None = None) -> str:
|
||||
try:
|
||||
run = await agent.arun(message, stream=False, session_id=sid)
|
||||
response_text = run.content if hasattr(run, "content") else str(run)
|
||||
except (httpx.ConnectError, httpx.ReadError, ConnectionError) as exc:
|
||||
logger.error("Ollama disconnected: %s", exc)
|
||||
return "Ollama appears to be disconnected. Check that ollama serve is running."
|
||||
except Exception as exc:
|
||||
logger.error("Session: agent.arun() failed: %s", exc)
|
||||
return "I'm having trouble reaching my language model right now. Please try again shortly."
|
||||
@@ -111,6 +116,11 @@ async def chat_with_tools(message: str, session_id: str | None = None):
|
||||
|
||||
try:
|
||||
return await agent.arun(message, stream=False, session_id=sid)
|
||||
except (httpx.ConnectError, httpx.ReadError, ConnectionError) as exc:
|
||||
logger.error("Ollama disconnected: %s", exc)
|
||||
return _ErrorRunOutput(
|
||||
"Ollama appears to be disconnected. Check that ollama serve is running."
|
||||
)
|
||||
except Exception as exc:
|
||||
logger.error("Session: agent.arun() failed: %s", exc)
|
||||
# Return a duck-typed object that callers can handle uniformly
|
||||
@@ -133,6 +143,11 @@ async def continue_chat(run_output, session_id: str | None = None):
|
||||
|
||||
try:
|
||||
return await agent.acontinue_run(run_response=run_output, stream=False, session_id=sid)
|
||||
except (httpx.ConnectError, httpx.ReadError, ConnectionError) as exc:
|
||||
logger.error("Ollama disconnected: %s", exc)
|
||||
return _ErrorRunOutput(
|
||||
"Ollama appears to be disconnected. Check that ollama serve is running."
|
||||
)
|
||||
except Exception as exc:
|
||||
logger.error("Session: agent.acontinue_run() failed: %s", exc)
|
||||
return _ErrorRunOutput(f"Error continuing run: {exc}")
|
||||
|
||||
Reference in New Issue
Block a user