-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_server.py
More file actions
28 lines (22 loc) · 805 Bytes
/
run_server.py
File metadata and controls
28 lines (22 loc) · 805 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 fastapi import FastAPI, HTTPException
from pydantic import BaseModel
from symphony.core.pipeline import Pipeline
app = FastAPI(title="Symphony Query Engine")
pipeline = Pipeline()
class Query(BaseModel):
text: str
class Answer(BaseModel):
result: str
@app.post("/query", response_model=Answer)
async def process_query(query: Query):
"""Process a natural language query and return the answer."""
if not query.text.strip():
raise HTTPException(status_code=400, detail="Query cannot be empty")
try:
result = pipeline.run_query(query.text)
return Answer(result=result)
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8001)