File size: 1,429 Bytes
2d1ee5e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
49
50
51
52
53
import nbformat as nbf

# Create a new notebook
nb = nbf.v4.new_notebook()

# Add cells
nb.cells = [
    nbf.v4.new_markdown_cell("# Demo: AI-Powered Scientific Research Companion\nThis notebook demonstrates how to use the `Dispatcher` to search for papers, retrieve reproducible notebook cells, and fetch a knowledge graph."),
    nbf.v4.new_code_cell("""\
from orchestrator.dispatcher import Dispatcher

# Initialize dispatcher
dispatcher = Dispatcher()

# Example query
query = "CRISPR delivery"

# 1. Search for papers
papers = dispatcher.search_papers(query, limit=3)
print("Papers found:")
for p in papers:
    print(f"- {p['title']} (ID: {p['id']})")
"""),
    nbf.v4.new_code_cell("""\
# 2. Retrieve notebook cells for the first paper
if papers:
    first_id = papers[0]['id']
    cells = dispatcher.get_notebook_cells(first_id)
    print(f"Notebook cells for paper {first_id}:")
    for i, cell in enumerate(cells, 1):
        print(f"Cell {i}:")
        print(cell)
        print("------")
"""),
    nbf.v4.new_code_cell("""\
# 3. Fetch knowledge graph for the first paper
if papers:
    graph = dispatcher.get_graph(first_id)
    print("Graph nodes:")
    for node in graph.get("nodes", []):
        print(node)
    print("Graph edges:")
    for edge in graph.get("edges", []):
        print(edge)
""")
]

# Save the notebook
nb_path = "/mnt/data/demo.ipynb"
with open(nb_path, "w") as f:
    nbf.write(nb, f)

nb_path