61 lines
1.8 KiB
Python
61 lines
1.8 KiB
Python
# api/routes/chat_ai.py
|
|
|
|
from fastapi import APIRouter, Depends, HTTPException
|
|
from api.models.requests import ChatRequest, ChatMessage,SurveyRequest
|
|
from api.models.responses import ChatResponse,SurveyAgentResponse
|
|
from api.dependencies.auth import get_api_key
|
|
from src.llm.orchestrator import DroneBot, Message # Adjust import as needed
|
|
from src.llm.agent.flight_assesment import DroneAssessmentAgent
|
|
import json
|
|
|
|
router = APIRouter(
|
|
prefix="/chat",
|
|
tags=["chat"]
|
|
)
|
|
|
|
@router.post("/booking-assistant", response_model=ChatResponse)
|
|
async def chat_ai(
|
|
request: ChatRequest,
|
|
_: str = Depends(get_api_key)
|
|
):
|
|
"""Chat with DroneBot using query and history."""
|
|
try:
|
|
# Convert to internal Message format
|
|
history = [Message(role=msg.role, content=msg.content) for msg in request.history]
|
|
|
|
# Initialize DroneBot with history
|
|
bot = DroneBot(history=history, use_openai_as_fallback=True)
|
|
|
|
# Get response
|
|
result = bot.chat(request.query)
|
|
|
|
return ChatResponse(
|
|
status="success",
|
|
message=result["final_message"]
|
|
)
|
|
except Exception as e:
|
|
raise HTTPException(
|
|
status_code=500,
|
|
detail=str(e)
|
|
)
|
|
|
|
|
|
@router.post("/analyse-survey", response_model=SurveyAgentResponse)
|
|
async def run_survey_agent(
|
|
request: SurveyRequest,
|
|
_: str = Depends(get_api_key)
|
|
):
|
|
"""Chat with DroneBot using query and history."""
|
|
try:
|
|
from test2 import booking_form_input
|
|
agent = DroneAssessmentAgent()
|
|
result = await agent.run(booking_form_input)
|
|
return SurveyAgentResponse(
|
|
status="success",
|
|
result=result
|
|
)
|
|
except Exception as e:
|
|
raise HTTPException(
|
|
status_code=500,
|
|
detail=str(e)
|
|
) |