Spaces:
Sleeping
Sleeping
| from fastapi import FastAPI | |
| from pydantic import BaseModel | |
| from my_agent.agent import build_graph | |
| import pandas as pd | |
| from typing import Optional | |
| from my_agent.utils.initial_interaction import BusinessInteractionChatbot | |
| app = FastAPI() | |
| interaction_chatbot = BusinessInteractionChatbot() | |
| graph = build_graph() | |
| class RequestInput(BaseModel): | |
| query: list | |
| preferred_topics: Optional[list] = [] | |
| class UserMessage(BaseModel): | |
| message: str | |
| details_for_brainstrom = {} | |
| def business_chat(msg: UserMessage): | |
| global details_for_brainstrom | |
| response = interaction_chatbot.chat(msg.message) | |
| if interaction_chatbot.is_complete(response): | |
| details = interaction_chatbot.extract_details() | |
| details_for_brainstrom = details | |
| return {"response": response, "business_details": details, "complete": True} | |
| return {"response": response, "complete": False} | |
| def run_graph(input_data: RequestInput): | |
| # business_details = details_for_brainstrom | |
| result = graph.invoke({'topic' : input_data.query , 'business_details': details_for_brainstrom}) | |
| # RequestInput.preferred_topics=result['preferred_topics'] | |
| return {'final_story': result['final_story'], | |
| 'business_details':result['business_details'], | |
| } | |