forked from UTSAVS26/PyVerse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
42 lines (34 loc) · 1.2 KB
/
Copy pathmain.py
File metadata and controls
42 lines (34 loc) · 1.2 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from fastapi import FastAPI, Request
from pydantic import BaseModel
from agents.intent_classifier import IntentClassifierAgent
from agents.router import RoutingAgent
from agents.notifier import NotifyAgent
from db.database import engine
from db.models import Base, MessageLog
from db.database import SessionLocal
from utils.logger import logger
import asyncio
app = FastAPI(title="AI Multi-Agent Chat Support System")
class ChatRequest(BaseModel):
user: str
message: str
@app.on_event("startup")
async def startup():
async with engine.begin() as conn:
await conn.run_sync(Base.metadata.create_all)
@app.post("/chat/")
async def chat(req: ChatRequest):
intent = IntentClassifierAgent.classify(req.message)
logger.info(f"Intent classified as: {intent}")
response = await RoutingAgent.route(intent, req.user, req.message)
async with SessionLocal() as session:
msg_log = MessageLog(
user=req.user,
intent=intent,
message=req.message,
response=response
)
session.add(msg_log)
await session.commit()
asyncio.create_task(NotifyAgent.send(req.user, response))
return {"intent": intent, "response": response}