add rag; fix estimation service
This commit is contained in:
parent
ada7788516
commit
47cc1541ed
8 changed files with 226 additions and 39 deletions
|
|
@ -26,8 +26,8 @@ class Applicant(BaseModel):
|
|||
applicant: int
|
||||
firstName: str
|
||||
lastName: str
|
||||
midName: str
|
||||
phone: str
|
||||
midName: Optional[str] = Field("", description="Middle name")
|
||||
phone: Optional[str] = Field("", description="Phone number")
|
||||
gender: str
|
||||
dob: date
|
||||
nicotine: bool
|
||||
|
|
@ -38,7 +38,7 @@ class Applicant(BaseModel):
|
|||
class Plan(BaseModel):
|
||||
id: int
|
||||
coverage: int
|
||||
tier: str
|
||||
tier: Optional[str] = Field(None, description="Tier assignment")
|
||||
|
||||
class Medication(BaseModel):
|
||||
applicant: int
|
||||
|
|
@ -72,14 +72,14 @@ class PHQ(BaseModel):
|
|||
conditions: List[Condition]
|
||||
|
||||
class Address(BaseModel):
|
||||
address1: str
|
||||
address2: str
|
||||
city: str
|
||||
state: str
|
||||
zipcode: str
|
||||
address1: Optional[str] = Field("", description="Address line 1")
|
||||
address2: Optional[str] = Field("", description="Address line 2")
|
||||
city: Optional[str] = Field("", description="City")
|
||||
state: Optional[str] = Field("", description="State")
|
||||
zipcode: Optional[str] = Field("", description="Zip code")
|
||||
|
||||
class EstimationRequest(BaseModel):
|
||||
uid: str
|
||||
uid: Optional[str] = Field(None, description="Unique identifier")
|
||||
applicants: List[Applicant]
|
||||
plans: List[Plan]
|
||||
phq: PHQ
|
||||
|
|
|
|||
|
|
@ -106,7 +106,8 @@ async def estimate(request: models.EstimationRequest):
|
|||
# Step 2: Check if DTQ → reject application
|
||||
if underwriting_result["combined"].get("dtq"):
|
||||
# For DTQ cases, call external reject API and return rejected status
|
||||
reject_response = await reject_application(request.uid)
|
||||
if request.uid:
|
||||
reject_response = await reject_application(request.uid)
|
||||
return models.EstimationResponse(
|
||||
status="rejected",
|
||||
details=models.EstimationDetails(
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue