mgbam commited on
Commit
3637999
·
verified ·
1 Parent(s): 0a3aede

Update mcp/orchestrator.py

Browse files
Files changed (1) hide show
  1. 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
- async def orchestrate_search(query: str) -> dict:
11
- # Fetch results in parallel (use asyncio.gather for speed)
12
- arxiv_results = await fetch_arxiv(query)
13
- pubmed_results = await fetch_pubmed(query)
 
 
 
14
  all_papers = arxiv_results + pubmed_results
15
- # Semantic ranking (use OpenAI embeddings or similar)
16
- # ...
17
- # NLP: extract keywords/drugs
18
- keywords = extract_keywords(" ".join([p['summary'] for p in all_papers]))
19
- # UMLS enrichment
20
- umls_results = [await lookup_umls(k) for k in keywords]
21
- # Drug safety
22
- drug_data = [await fetch_drug_safety(k) for k in keywords]
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 = "") -> dict:
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}