File size: 872 Bytes
8ca6452 3f5be06 |
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 |
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
import asyncio
from ai_core import AICore
app = FastAPI()
# Initialize the AI core
ai_core = AICore()
class QueryRequest(BaseModel):
query: str
class QueryResponse(BaseModel):
insights: list
response: str
security_level: int
safety_checks: dict
health_status: dict
encrypted_query: str
@app.post("/query", response_model=QueryResponse)
async def handle_query(request: QueryRequest):
try:
response = await ai_core.generate_response(request.query)
return QueryResponse(**response)
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
@app.on_event("shutdown")
async def shutdown_event():
await ai_core.shutdown()
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=7860) |