Spaces:
Sleeping
Sleeping
Update orchestrator/dispatcher.py
Browse files- orchestrator/dispatcher.py +21 -22
orchestrator/dispatcher.py
CHANGED
|
@@ -1,53 +1,52 @@
|
|
| 1 |
# File: orchestrator/dispatcher.py
|
| 2 |
-
import uuid
|
| 3 |
import yaml
|
| 4 |
from orchestrator.client import MCPClient
|
| 5 |
|
| 6 |
-
|
| 7 |
class Dispatcher:
|
| 8 |
"""
|
| 9 |
-
Coordinates calls to
|
| 10 |
"""
|
| 11 |
-
def __init__(self, config_path=
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
self.
|
| 16 |
-
self.
|
| 17 |
-
self.
|
|
|
|
| 18 |
|
| 19 |
def search_papers(self, query: str, limit: int = 5):
|
| 20 |
"""
|
| 21 |
-
|
| 22 |
"""
|
| 23 |
-
|
| 24 |
try:
|
| 25 |
-
|
| 26 |
except Exception:
|
| 27 |
pass
|
| 28 |
try:
|
| 29 |
-
|
| 30 |
except Exception:
|
| 31 |
pass
|
| 32 |
-
#
|
| 33 |
-
unique = {
|
| 34 |
return list(unique.values())[:limit]
|
| 35 |
|
| 36 |
def get_notebook_cells(self, paper_id: str):
|
| 37 |
"""
|
| 38 |
-
Retrieve code cells
|
| 39 |
"""
|
| 40 |
try:
|
| 41 |
-
|
| 42 |
-
return
|
| 43 |
except Exception:
|
| 44 |
return []
|
| 45 |
|
| 46 |
def get_graph(self, paper_id: str):
|
| 47 |
"""
|
| 48 |
-
Retrieve a knowledge graph
|
| 49 |
"""
|
| 50 |
try:
|
| 51 |
-
return self.chroma.call(
|
| 52 |
except Exception:
|
| 53 |
-
return {
|
|
|
|
| 1 |
# File: orchestrator/dispatcher.py
|
|
|
|
| 2 |
import yaml
|
| 3 |
from orchestrator.client import MCPClient
|
| 4 |
|
|
|
|
| 5 |
class Dispatcher:
|
| 6 |
"""
|
| 7 |
+
Coordinates calls to MCP servers for search, notebook execution, and graph retrieval.
|
| 8 |
"""
|
| 9 |
+
def __init__(self, config_path='config.yaml'):
|
| 10 |
+
with open(config_path, 'r') as f:
|
| 11 |
+
cfg = yaml.safe_load(f)
|
| 12 |
+
servers = cfg.get('mcp_servers', {})
|
| 13 |
+
self.web = MCPClient(servers.get('web_search', ''))
|
| 14 |
+
self.pubmed = MCPClient(servers.get('pubmed', ''))
|
| 15 |
+
self.chroma = MCPClient(servers.get('chroma', ''))
|
| 16 |
+
self.runner = MCPClient(servers.get('python_run', ''))
|
| 17 |
|
| 18 |
def search_papers(self, query: str, limit: int = 5):
|
| 19 |
"""
|
| 20 |
+
Aggregate results from web and PubMed MCP endpoints.
|
| 21 |
"""
|
| 22 |
+
papers = []
|
| 23 |
try:
|
| 24 |
+
papers += self.web.call('web_search.search', {'q': query}) or []
|
| 25 |
except Exception:
|
| 26 |
pass
|
| 27 |
try:
|
| 28 |
+
papers += self.pubmed.call('metatool.query', {'source': 'PubMed', 'q': query}) or []
|
| 29 |
except Exception:
|
| 30 |
pass
|
| 31 |
+
# dedupe
|
| 32 |
+
unique = {p['id']: p for p in papers if 'id' in p}
|
| 33 |
return list(unique.values())[:limit]
|
| 34 |
|
| 35 |
def get_notebook_cells(self, paper_id: str):
|
| 36 |
"""
|
| 37 |
+
Retrieve reproducible code cells from Python-run MCP server.
|
| 38 |
"""
|
| 39 |
try:
|
| 40 |
+
result = self.runner.call('mcp-run-python.execute', {'paper_id': paper_id})
|
| 41 |
+
return result.get('cells', [])
|
| 42 |
except Exception:
|
| 43 |
return []
|
| 44 |
|
| 45 |
def get_graph(self, paper_id: str):
|
| 46 |
"""
|
| 47 |
+
Retrieve a knowledge graph for a paper from the Chroma MCP server.
|
| 48 |
"""
|
| 49 |
try:
|
| 50 |
+
return self.chroma.call('chroma.query_graph', {'id': paper_id}) or {'nodes': [], 'edges': []}
|
| 51 |
except Exception:
|
| 52 |
+
return {'nodes': [], 'edges': []}
|