import ast import json import logging from fastapi import APIRouter from fastapi.responses import StreamingResponse from api.stored_data import stored_data from src.genai.analytics_chatbot.agent import ChatbotAgent from src.genai.analytics_chatbot.utils.utils import process_query from api.schemas.analytics_chatbot import UserMessage app_logger = logging.getLogger("app_logger") error_logger = logging.getLogger("error_logger") router = APIRouter() agent=ChatbotAgent() graph = agent.chatbot_graph() @router.get("/analytics-chatbot") def get_analytics(msg:str): user_query=process_query(msg) config={"configurable": {"thread_id": "analytics-chatbot-thread"}} try: result=graph.invoke({'messages':user_query},config=config) return { 'response': result['response'], 'endpoint': result['endpoint'] } except Exception as e: print(e)