diff --git a/requirements.txt b/requirements.txt index 10f8a0a..3205f5b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -33,4 +33,8 @@ redis>=5.0.0 # General numpy>=2.4.0 -torch>=2.11.0 \ No newline at end of file +torch>=2.11.0 + +# FastAPI +fastapi>=0.110.0 +uvicorn>=0.29.0 \ No newline at end of file diff --git a/src/agent/graph.py b/src/agent/graph.py index b42e758..97d6c1f 100644 --- a/src/agent/graph.py +++ b/src/agent/graph.py @@ -35,4 +35,4 @@ graph.set_finish_point("assembly") # Compile -app = graph.compile() \ No newline at end of file +agent = graph.compile() \ No newline at end of file diff --git a/src/api/main.py b/src/api/main.py new file mode 100644 index 0000000..c455dce --- /dev/null +++ b/src/api/main.py @@ -0,0 +1,35 @@ +from fastapi import FastAPI, HTTPException +from contextlib import asynccontextmanager +from src.agent.graph import agent +from pydantic import BaseModel + +class QueryRequest(BaseModel): + query: str + +@asynccontextmanager +async def lifespan(app): + yield +app = FastAPI(lifespan=lifespan) + +@app.post("/query") +async def query(request: QueryRequest): + try: + result = agent.invoke({ + "query": request.query, + "search_query": None, + "cache_hit": False, + "abstracts": [], + "llm_response": None, + "claims": None, + "scored_claims": None, + "confidence_score": None, + "final_response": None + }) + + return result + except Exception as e: + raise HTTPException(status_code=500, detail=f"Inference failed: {str(e)}") + +@app.get("/health") +async def health(): + return {"status": "ok"} \ No newline at end of file diff --git a/tests/pipeline_runner.py b/tests/pipeline_runner.py index 8642a98..c038a3c 100644 --- a/tests/pipeline_runner.py +++ b/tests/pipeline_runner.py @@ -1,8 +1,8 @@ -from src.agent.graph import app +from src.agent.graph import agent import sys def main(): - result = app.invoke({ + result = agent.invoke({ "query": "What are the first line treatments for atrial fibrillation?", "cache_hit": False, "abstracts": [],