trygithubactions / api /routers /context_analysis.py
subashpoudel's picture
Included CI CD
583f6dd
raw
history blame
1.06 kB
import ast
from fastapi import APIRouter, Depends
from pydantic import BaseModel
from api.stored_data import stored_data
from src.genai.context_analysis_agent.agent import IntroductionChatbot
router = APIRouter()
class UserMessage(BaseModel):
message: str
context_analysis_graph = IntroductionChatbot()
@router.post("/context-analysis")
def context_analysis(msg: UserMessage):
response = context_analysis_graph.chat(msg.message)
if context_analysis_graph.is_complete(response):
details = context_analysis_graph.extract_details()
if type(details) != dict:
details = details.model_dump()
print('Business_details:',details)
if isinstance(details, str):
details= ast.literal_eval(details)
print('Details Type:',type(details))
# save_to_db(details)
stored_data['business_details'] = details
context_analysis_graph.reset()
return {"response": response, "business_details": details, "complete": True}
return {"response": response, "complete": False}