add name to context
This commit is contained in:
parent
0e6cb8bbd0
commit
37920ef259
3 changed files with 15 additions and 14 deletions
|
|
@ -54,7 +54,11 @@ async def init_chat(request: models.InitializeChatRequest):
|
||||||
elif request.context and request.context.applicationDTO:
|
elif request.context and request.context.applicationDTO:
|
||||||
application = json.loads(base64.b64decode(request.context.applicationDTO).decode())
|
application = json.loads(base64.b64decode(request.context.applicationDTO).decode())
|
||||||
|
|
||||||
result = await chat_service.initialize_chat(str(request.userId), application)
|
name = None
|
||||||
|
if request.context and request.context.name:
|
||||||
|
name = request.context.name
|
||||||
|
|
||||||
|
result = await chat_service.initialize_chat(str(request.userId), application, name.first_name)
|
||||||
return models.InitializeChatResponse(
|
return models.InitializeChatResponse(
|
||||||
session_id=result["session_id"],
|
session_id=result["session_id"],
|
||||||
answer=result["answer"],
|
answer=result["answer"],
|
||||||
|
|
|
||||||
|
|
@ -85,10 +85,15 @@ class EstimationResponse(BaseModel):
|
||||||
details: EstimationDetails
|
details: EstimationDetails
|
||||||
results: List[EstimationResult]
|
results: List[EstimationResult]
|
||||||
|
|
||||||
|
class UserNameContext(BaseModel):
|
||||||
|
first_name: str
|
||||||
|
last_name: str
|
||||||
|
|
||||||
class InsuranceChatContext(BaseModel):
|
class InsuranceChatContext(BaseModel):
|
||||||
page: str
|
page: str
|
||||||
application: dict | None = None
|
application: dict | None = None
|
||||||
applicationDTO: str | None = None
|
applicationDTO: str | None = None
|
||||||
|
name: UserNameContext | None = None
|
||||||
|
|
||||||
class InsuranceChatRequest(BaseModel):
|
class InsuranceChatRequest(BaseModel):
|
||||||
userId: str | int | None = None
|
userId: str | int | None = None
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
import json
|
import json
|
||||||
|
from datetime import datetime
|
||||||
from typing import Dict, Any, List, Optional
|
from typing import Dict, Any, List, Optional
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
|
|
||||||
from src.models import ApplicantParam, ChatHook, PlansParam, InsuranceChatContext
|
from src.models import ApplicantParam, ChatHook, PlansParam
|
||||||
from .session_service import session_service
|
from .session_service import session_service
|
||||||
from ..api.v1.models import Source, HistoryItem
|
from ..api.v1.models import Source, HistoryItem
|
||||||
from ..config import settings
|
from ..config import settings
|
||||||
from ..database import Session, UserSession
|
from ..database import Session, UserSession
|
||||||
from datetime import datetime
|
|
||||||
|
|
||||||
# vars: name
|
# vars: name
|
||||||
INIT_MESSAGES = [
|
INIT_MESSAGES = [
|
||||||
|
|
@ -173,7 +173,7 @@ class ChatService:
|
||||||
session.add(user_session)
|
session.add(user_session)
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
async def initialize_chat(self, uid: str, application):
|
async def initialize_chat(self, uid: str, application, name):
|
||||||
session_id = await self.get_user_session(uid)
|
session_id = await self.get_user_session(uid)
|
||||||
if not session_id or not await session_service.validate_session(session_id):
|
if not session_id or not await session_service.validate_session(session_id):
|
||||||
session_id = await session_service.create_session(agent_id=settings.TALESTORM_AGENT_ID)
|
session_id = await session_service.create_session(agent_id=settings.TALESTORM_AGENT_ID)
|
||||||
|
|
@ -183,6 +183,7 @@ class ChatService:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
if not name:
|
||||||
name = application["applicants"][0]["firstName"]
|
name = application["applicants"][0]["firstName"]
|
||||||
except:
|
except:
|
||||||
return {
|
return {
|
||||||
|
|
@ -210,15 +211,6 @@ class ChatService:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async def process_insurance_chat(self, message: str, session_id: Optional[str] = None, uid: Optional[str] = None, current_page: Optional[str] = None, application: Optional[dict] = None) -> Dict[str, Any]:
|
async def process_insurance_chat(self, message: str, session_id: Optional[str] = None, uid: Optional[str] = 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:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue