File size: 863 Bytes
3002e1b
 
 
 
 
 
 
872d043
3002e1b
 
 
 
 
 
 
 
 
8ce97f0
 
 
3002e1b
 
872d043
3002e1b
872d043
3002e1b
 
872d043
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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'],
        }
    except Exception as e:
        print(e)