-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
28 lines (22 loc) · 690 Bytes
/
server.py
File metadata and controls
28 lines (22 loc) · 690 Bytes
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
from dotenv import load_dotenv
load_dotenv()
from rag_queue.queue.worker import process_query
from .client.rq_client import queue
from fastapi import FastAPI, Query
app = FastAPI()
@app.get("/")
def read_root():
return {"status": "Server is up and running!"}
@app.post("/chat")
def chat(
query: str = Query(..., description="The question to ask the AI assistant.")
):
job = queue.enqueue(process_query, query)
return {"status": "queued", "job_id": job.id}
@app.get("/job-status")
def get_job_result(
job_id: str = Query(..., description="Job ID")
):
job = queue.fetch_job(job_id = job_id)
result = job.return_value()
return {"result": result}