forked from PG219/PharmaMind
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.py
More file actions
48 lines (39 loc) · 1.34 KB
/
api.py
File metadata and controls
48 lines (39 loc) · 1.34 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
import uvicorn
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from src.orchestration.master_agent import get_master_chain
from src.schemas.final_report_schema import FinalReport
app = FastAPI(
title="PharmaMind API",
description="API for running the PharmaMind drug repurposing agent.",
version="1.0.0"
)
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.get("/")
async def get_root():
return {"message": "PharmaMind API is running. Go to /docs for documentation."}
@app.get("/report/{drug_name}")
async def get_drug_report(drug_name: str):
print(f"Received request for: {drug_name}")
master_chain = get_master_chain()
result = master_chain.invoke({"drug_name": drug_name})
if isinstance(result, FinalReport):
print(f"Successfully generated report for: {drug_name}")
return result.model_dump()
else:
return {"error": "Unexpected output type", "result": str(result)}
if __name__ == "__main__":
print("Starting PharmaMind API server on http://127.0.0.1:8000")
print("Go to http://127.0.0.1:8000/docs for the interactive API documentation.")
uvicorn.run(
"api:app",
host="127.0.0.1",
port=8000,
reload=True
)