add webpage info
This commit is contained in:
parent
e4d2e64ce7
commit
959fd1ac86
5 changed files with 83 additions and 8 deletions
|
|
@ -1,11 +1,13 @@
|
|||
import json
|
||||
import httpx
|
||||
from typing import Dict, Any, List, Optional
|
||||
|
||||
from src.models import ApplicantParam, ChatHook, PlansParam
|
||||
from ..config import settings
|
||||
import httpx
|
||||
|
||||
from src.models import ApplicantParam, ChatHook, PlansParam, InsuranceChatContext
|
||||
from .session_service import session_service
|
||||
from ..api.v1.models import Source, HistoryItem
|
||||
from ..config import settings
|
||||
|
||||
|
||||
class ChatService:
|
||||
"""Service for handling chat functionality with talestorm-ai"""
|
||||
|
|
@ -93,7 +95,7 @@ class ChatService:
|
|||
continue
|
||||
|
||||
kind = item.get("kind", "")
|
||||
|
||||
|
||||
# Handle request messages (user input)
|
||||
if kind == "request":
|
||||
parts = item.get("parts", [])
|
||||
|
|
@ -108,15 +110,18 @@ class ChatService:
|
|||
elif kind == "response":
|
||||
parts = item.get("parts", [])
|
||||
for part in parts:
|
||||
if part.get("part_kind") == "text":
|
||||
if part.get("tool_name") == "final_result":
|
||||
tool_args = json.loads(part.get("args"))
|
||||
|
||||
history.append(HistoryItem(
|
||||
role="assistant",
|
||||
message=part.get("content", "")
|
||||
message=tool_args.get("answer", "")
|
||||
))
|
||||
|
||||
return history
|
||||
return []
|
||||
except Exception as e:
|
||||
# raise e
|
||||
print(f"Error getting chat history: {e}")
|
||||
return []
|
||||
|
||||
|
|
@ -130,7 +135,7 @@ class ChatService:
|
|||
# For now, return empty list - this would be populated when RAG is implemented
|
||||
return []
|
||||
|
||||
async def process_insurance_chat(self, message: str, session_id: Optional[str] = None, uid: Optional[int] = None) -> Dict[str, Any]:
|
||||
async def process_insurance_chat(self, message: str, session_id: Optional[str] = None, uid: Optional[int] = None, current_page: Optional[str] = None) -> Dict[str, Any]:
|
||||
"""Process an insurance chat request"""
|
||||
try:
|
||||
if not session_id:
|
||||
|
|
@ -143,6 +148,8 @@ class ChatService:
|
|||
if uid:
|
||||
user_state = await self.get_user_state(uid)
|
||||
instructions += f"\n\n# User Information\nApplication state (None means that application was not sent or pending):\n{user_state}"
|
||||
if current_page:
|
||||
instructions += f"\n\n# User now is currently on page:"
|
||||
|
||||
chat_response = await self.send_message(session_id, message, instructions)
|
||||
history = await self.get_chat_history(session_id)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue