setup assisant bot
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,38 @@
|
||||
# api/routes/chat_ai.py
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from api.models.requests import ChatRequest, ChatMessage
|
||||
from api.models.responses import ChatResponse
|
||||
from api.dependencies.auth import get_api_key
|
||||
from src.llm.orchestrator import DroneBot, Message # Adjust import as needed
|
||||
|
||||
router = APIRouter(
|
||||
prefix="/chat-ai",
|
||||
tags=["chat"]
|
||||
)
|
||||
|
||||
@router.post("", 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)
|
||||
)
|
||||
Reference in New Issue
Block a user