setup assisant bot

This commit is contained in:
OwusuBlessing
2025-07-24 14:27:56 +01:00
commit 95d357de60
62 changed files with 1106 additions and 0 deletions
View File
Binary file not shown.
Binary file not shown.
+19
View File
@@ -0,0 +1,19 @@
from pydantic_settings import BaseSettings
from functools import lru_cache
from config import Config
class Settings(BaseSettings):
API_V1_STR: str = "/api/v1"
PROJECT_NAME: str = "drone bot API"
VERSION: str = "1.0.0"
DESCRIPTION: str = ""
# API Key validation
API_KEY_ACCESS: str = Config.API_KEY
class Config:
case_sensitive = True
@lru_cache()
def get_settings() -> Settings:
return Settings()
Binary file not shown.
+25
View File
@@ -0,0 +1,25 @@
from fastapi import HTTPException, Depends, Security
from fastapi.security import APIKeyHeader
from api.models.requests import BaseRequest
from config import Config
api_key_header = APIKeyHeader(name="Authorization", auto_error=False)
async def get_api_key(api_key_header: str = Security(api_key_header)) -> str:
"""Validate API key from header"""
if not api_key_header or not api_key_header.startswith('Bearer '):
raise HTTPException(
status_code=401,
detail={"error": "Unauthorized", "message": "API key is missing or invalid."}
)
token = api_key_header.split(' ')[1]
if token != Config.API_KEY:
raise HTTPException(
status_code=401,
detail={"error": "Unauthorized", "message": "API key does not match."}
)
return token
Binary file not shown.
Binary file not shown.
+15
View File
@@ -0,0 +1,15 @@
# api/models/requests.py
from pydantic import BaseModel
from typing import List
class BaseRequest(BaseModel):
pass
class ChatMessage(BaseModel):
role: str # "human" or "ai"
content: str
class ChatRequest(BaseModel):
query: str
history: List[ChatMessage] = []
+8
View File
@@ -0,0 +1,8 @@
# api/models/responses.py
from pydantic import BaseModel
class ChatResponse(BaseModel):
status: str
message: str
View File
Binary file not shown.
Binary file not shown.
+38
View File
@@ -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)
)