add rag; fix estimation service

This commit is contained in:
ipu 2025-07-25 21:23:11 +03:00
parent ada7788516
commit 47cc1541ed
8 changed files with 226 additions and 39 deletions

View file

@ -100,22 +100,15 @@ class ChatService:
async def process_insurance_chat(self, message: str, session_id: Optional[str] = None) -> Dict[str, Any]:
"""Process an insurance chat request"""
try:
# Create session if not provided
if not session_id:
session_id = await session_service.create_session()
# Validate session if provided
elif not await session_service.validate_session(session_id):
# Create new session if invalid
session_id = await session_service.create_session()
# Send message to talestorm-ai
chat_response = await self.send_message(session_id, message)
# Get chat history
history = await self.get_chat_history(session_id)
# Extract sources from the response (placeholder for RAG implementation)
sources = self._extract_sources_from_response(chat_response.get("message", ""))
return {

View file

@ -56,29 +56,16 @@ class SessionService:
async def create_session(self, agent_id: Optional[str] = None) -> Optional[str]:
"""Create a new chat session in talestorm-ai"""
async with await self.get_client() as client:
try:
# Use provided agent_id, then configured agent_id, then fallback to default
if not agent_id:
if self.agent_id:
agent_id = self.agent_id
else:
default_agent = await self.get_default_agent()
if not default_agent:
# Create a simple session ID for now
return str(uuid.uuid4())
agent_id = str(default_agent["id"])
# Create session with talestorm-ai
response = await client.post("/sessions/", params={"agent_id": agent_id})
if response.status_code == 200:
session_data = response.json()
return str(session_data["id"])
if not agent_id:
if self.agent_id:
agent_id = self.agent_id
else:
# Fallback to local session ID
return str(uuid.uuid4())
except Exception:
# Fallback to local session ID
return str(uuid.uuid4())
agent_id = settings.TALESTORM_AGENT_ID
response = await client.post("/sessions/", params={"agent_id": agent_id})
session_data = response.json()
return str(session_data["id"])
async def get_session(self, session_id: str) -> Optional[Dict[str, Any]]:
"""Get session details from talestorm-ai"""