fix timeout in chat

This commit is contained in:
ipu 2025-07-28 17:22:52 +03:00
parent 1afa22ea13
commit 4f82307cd9

View file

@ -19,7 +19,8 @@ class ChatService:
return httpx.AsyncClient( return httpx.AsyncClient(
base_url=self.base_url, base_url=self.base_url,
headers=headers headers=headers,
timeout=httpx.Timeout(60.0, connect=10.0) # 30s total timeout, 10s connect timeout
) )
async def send_message(self, session_id: str, message: str) -> Dict[str, Any]: async def send_message(self, session_id: str, message: str) -> Dict[str, Any]:
@ -39,6 +40,7 @@ class ChatService:
print(response.json()) print(response.json())
raise Exception(f"Error sending message to talestorm-ai: {response.status_code} {response.json()}") raise Exception(f"Error sending message to talestorm-ai: {response.status_code} {response.json()}")
except Exception as e: except Exception as e:
# raise e
return { return {
"chat_session_id": session_id, "chat_session_id": session_id,
"message": f"I'm sorry, I'm experiencing technical difficulties. Please try again later. Error: {str(e)}" "message": f"I'm sorry, I'm experiencing technical difficulties. Please try again later. Error: {str(e)}"
@ -120,7 +122,7 @@ class ChatService:
} }
except Exception as e: except Exception as e:
raise e # raise e
return { return {
"session_id": session_id or "fallback-session", "session_id": session_id or "fallback-session",
"answer": f"I'm sorry, I'm experiencing technical difficulties. Please try again later. Error: {str(e)}", "answer": f"I'm sorry, I'm experiencing technical difficulties. Please try again later. Error: {str(e)}",