Initial commit from Martins Github
This commit is contained in:
24
app/routers/query.py
Normal file
24
app/routers/query.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from fastapi import APIRouter
|
||||
from pydantic import BaseModel
|
||||
from app.services import prometheus, alertmanager, ai
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
class QueryRequest(BaseModel):
|
||||
query: str
|
||||
|
||||
|
||||
@router.post("/query")
|
||||
async def query(req: QueryRequest):
|
||||
network_state, alerts = await _gather(req.query)
|
||||
response = await ai.answer(req.query, network_state, alerts)
|
||||
return {"response": response, "network_state": network_state, "alerts": alerts}
|
||||
|
||||
|
||||
async def _gather(query_text: str):
|
||||
import asyncio
|
||||
nfs_task = asyncio.create_task(prometheus.get_nf_status())
|
||||
alerts_task = asyncio.create_task(alertmanager.get_alerts())
|
||||
nfs, alerts = await asyncio.gather(nfs_task, alerts_task)
|
||||
return {"nfs": nfs}, alerts
|
||||
Reference in New Issue
Block a user