nsa9 commited on
Commit
b3dc0d3
·
verified ·
1 Parent(s): d07a39f

Create api.py

Browse files
Files changed (1) hide show
  1. api.py +40 -0
api.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # api.py
2
+ from fastapi import FastAPI
3
+ from pydantic import BaseModel
4
+ from agents import Orchestrator
5
+ from utils import load_json
6
+ import os
7
+
8
+ # Initialize FastAPI app
9
+ app = FastAPI()
10
+
11
+ # Load config and docs
12
+ HERE = os.path.dirname(__file__)
13
+ models_cfg = load_json(os.path.join(HERE, "models_config.json"))
14
+ pubmed = load_json(os.path.join(HERE, "sample_data", "pubmed_sample.json"))
15
+ patents = load_json(os.path.join(HERE, "sample_data", "patents_sample.json"))
16
+ docs = pubmed + patents
17
+
18
+ # Initialize orchestrator once
19
+ orch = Orchestrator(docs, {
20
+ "embed_model": models_cfg["embed_model"],
21
+ "summarizer_model": models_cfg["summarizer_model"]
22
+ })
23
+
24
+ # Define request schema
25
+ class QueryRequest(BaseModel):
26
+ query: str
27
+ top_k: int = 5
28
+
29
+ @app.post("/api/query")
30
+ async def query_endpoint(body: QueryRequest):
31
+ """
32
+ Programmatic endpoint for integrations.
33
+ Example POST body:
34
+ {
35
+ "query": "neutralizing antibody patents + clinical trials 2019-2024",
36
+ "top_k": 5
37
+ }
38
+ """
39
+ result = orch.run(body.query, top_k=body.top_k)
40
+ return result