Update mcp/orchestrator.py
Browse files- mcp/orchestrator.py +16 -16
mcp/orchestrator.py
CHANGED
@@ -7,22 +7,22 @@ from mcp.umls import lookup_umls
|
|
7 |
from mcp.openfda import fetch_drug_safety
|
8 |
from mcp.openai_utils import ai_summarize, ai_qa
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
14 |
all_papers = arxiv_results + pubmed_results
|
15 |
-
|
16 |
-
#
|
17 |
-
#
|
18 |
-
|
19 |
-
|
20 |
-
umls_results =
|
21 |
-
|
22 |
-
|
23 |
-
# Summarization
|
24 |
-
summary = await ai_summarize(" ".join([p['summary'] for p in all_papers]))
|
25 |
-
# Suggest reading (top links)
|
26 |
links = [p['link'] for p in all_papers[:3]]
|
27 |
return {
|
28 |
"papers": all_papers,
|
@@ -32,6 +32,6 @@ async def orchestrate_search(query: str) -> dict:
|
|
32 |
"suggested_reading": links,
|
33 |
}
|
34 |
|
35 |
-
async def answer_ai_question(question: str, context: str = "")
|
36 |
answer = await ai_qa(question, context)
|
37 |
return {"answer": answer}
|
|
|
7 |
from mcp.openfda import fetch_drug_safety
|
8 |
from mcp.openai_utils import ai_summarize, ai_qa
|
9 |
|
10 |
+
import asyncio
|
11 |
+
|
12 |
+
async def orchestrate_search(query: str):
|
13 |
+
# Fetch from arXiv and PubMed in parallel
|
14 |
+
arxiv_task = asyncio.create_task(fetch_arxiv(query))
|
15 |
+
pubmed_task = asyncio.create_task(fetch_pubmed(query))
|
16 |
+
arxiv_results, pubmed_results = await asyncio.gather(arxiv_task, pubmed_task)
|
17 |
all_papers = arxiv_results + pubmed_results
|
18 |
+
paper_text = " ".join([p['summary'] for p in all_papers])
|
19 |
+
keywords = extract_keywords(paper_text)[:8] # Limit for speed
|
20 |
+
# UMLS and OpenFDA in parallel
|
21 |
+
umls_tasks = [lookup_umls(k) for k in keywords]
|
22 |
+
drug_tasks = [fetch_drug_safety(k) for k in keywords]
|
23 |
+
umls_results = await asyncio.gather(*umls_tasks)
|
24 |
+
drug_data = await asyncio.gather(*drug_tasks)
|
25 |
+
summary = await ai_summarize(paper_text)
|
|
|
|
|
|
|
26 |
links = [p['link'] for p in all_papers[:3]]
|
27 |
return {
|
28 |
"papers": all_papers,
|
|
|
32 |
"suggested_reading": links,
|
33 |
}
|
34 |
|
35 |
+
async def answer_ai_question(question: str, context: str = ""):
|
36 |
answer = await ai_qa(question, context)
|
37 |
return {"answer": answer}
|