send application info to prompt

This commit is contained in:
ipu 2025-09-17 12:49:23 +03:00
parent 538ea04aa5
commit d61aac5813
2 changed files with 18 additions and 1 deletions

View file

@ -16,11 +16,17 @@ async def insurance_chat(request: models.InsuranceChatRequest):
if request.context and request.context.page: if request.context and request.context.page:
page_id = str(request.context.page).lower() page_id = str(request.context.page).lower()
current_page = await get_page_description(page_id) current_page = await get_page_description(page_id)
application = None
if request.context and request.context.application:
application = request.context.application
result = await chat_service.process_insurance_chat( result = await chat_service.process_insurance_chat(
message=request.message, message=request.message,
session_id=request.session_id, session_id=request.session_id,
uid=str(request.userId), uid=str(request.userId),
current_page=current_page, current_page=current_page,
application=application,
) )
return models.InsuranceChatResponse( return models.InsuranceChatResponse(

View file

@ -135,7 +135,7 @@ class ChatService:
# For now, return empty list - this would be populated when RAG is implemented # For now, return empty list - this would be populated when RAG is implemented
return [] return []
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]: async def process_insurance_chat(self, message: str, session_id: Optional[str] = None, uid: Optional[int] = None, current_page: Optional[str] = None, application: Optional[dict] = None) -> Dict[str, Any]:
"""Process an insurance chat request""" """Process an insurance chat request"""
try: try:
if not session_id: if not session_id:
@ -148,6 +148,17 @@ class ChatService:
if uid: if uid:
user_state = await self.get_user_state(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}" instructions += f"\n\n# User Information\nApplication state (None means that application was not sent or pending):\n{user_state}"
if application:
instructions += f"\n\n# User Application Info\n"
if application.get("plans", []):
plans_info = "User plans:\n"
for p in application["plans"]:
plans_info += f"{str(p)}\n"
instructions += plans_info
if application.get("phq", {}).get("effective_date", None):
effective_date = application.get("phq", {}).get("effective_date", None)
instructions += f"Plan effective date: {effective_date}"
if current_page: if current_page:
instructions += f"\n\n# User now is currently on page: {current_page}" instructions += f"\n\n# User now is currently on page: {current_page}"