Skip to content

Commit 1eeebed

Browse files
committed
Simplified toolkits as list of tools, enabled imports from root
1 parent d26745a commit 1eeebed

File tree

6 files changed

+44
-48
lines changed

6 files changed

+44
-48
lines changed

jupyter_ai_tools/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
1+
from .toolkits.code_execution import toolkit as exec_toolkit
2+
from .toolkits.file_system import toolkit as fs_toolkit
3+
from .toolkits.git import toolkit as git_toolkit
4+
from .toolkits.notebook import toolkit as nb_toolkit
5+
16
__version__ = "0.2.1"
27

8+
__all__ = [
9+
"fs_toolkit",
10+
"exec_toolkit",
11+
"git_toolkit",
12+
"nb_toolkit",
13+
]
314

415
def _jupyter_server_extension_points():
516
return [{"module": "jupyter_ai_tools"}]

jupyter_ai_tools/toolkits/code_execution.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import shlex
55
from typing import Optional
66

7-
from jupyter_ai.tools.models import Tool, Toolkit
8-
97

108
async def bash(command: str, timeout: Optional[int] = None) -> str:
119
"""Executes a bash command and returns the result
@@ -40,8 +38,6 @@ async def bash(command: str, timeout: Optional[int] = None) -> str:
4038
return f"Command timed out after {timeout} seconds"
4139

4240

43-
toolkit = Toolkit(
44-
name="code_execution_toolkit",
45-
description="Tools to execute code in different environments.",
46-
)
47-
toolkit.add_tool(Tool(callable=bash, execute=True))
41+
toolkit = [
42+
bash,
43+
]

jupyter_ai_tools/toolkits/file_system.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
import os
77
from typing import List, Optional
88

9-
from jupyter_ai.tools.models import Tool, Toolkit
10-
119
from ..utils import normalize_filepath
1210

1311

@@ -355,15 +353,12 @@ async def ls(path: str, ignore: Optional[List[str]] = None) -> str:
355353
except Exception as e:
356354
return f"Error: Failed to list directory: {str(e)}"
357355

358-
359-
toolkit = Toolkit(
360-
name="file_system_toolkit",
361-
description="Tools to do search, list, read, write and edit operations on files.",
362-
)
363-
toolkit.add_tool(Tool(callable=read, read=True))
364-
toolkit.add_tool(Tool(callable=edit, read=True, write=True))
365-
toolkit.add_tool(Tool(callable=write, write=True))
366-
toolkit.add_tool(Tool(callable=search_and_replace, read=True, write=True))
367-
toolkit.add_tool(Tool(callable=glob, read=True))
368-
toolkit.add_tool(Tool(callable=grep, read=True))
369-
toolkit.add_tool(Tool(callable=ls, read=True))
356+
toolkit = [
357+
read,
358+
edit,
359+
write,
360+
search_and_replace,
361+
glob,
362+
grep,
363+
ls,
364+
]

jupyter_ai_tools/toolkits/git.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import json
22
import os
33

4-
from jupyter_ai.tools.models import Tool, Toolkit
54
from jupyterlab_git.git import Git
65

76
from ..utils import normalize_filepath
@@ -175,15 +174,13 @@ async def git_get_repo_root(path: str) -> str:
175174
return f"❌ Not inside a Git repo. {res.get('message', '')}"
176175

177176

178-
toolkit = Toolkit(
179-
name="git_toolkit",
180-
description="Tools for working with Git repositories.",
181-
)
182-
toolkit.add_tool(Tool(callable=git_clone, execute=True))
183-
toolkit.add_tool(Tool(callable=git_status, read=True))
184-
toolkit.add_tool(Tool(callable=git_log, read=True))
185-
toolkit.add_tool(Tool(callable=git_pull, execute=True))
186-
toolkit.add_tool(Tool(callable=git_push, execute=True))
187-
toolkit.add_tool(Tool(callable=git_commit, execute=True))
188-
toolkit.add_tool(Tool(callable=git_add, execute=True))
189-
toolkit.add_tool(Tool(callable=git_get_repo_root, read=True))
177+
toolkit = [
178+
git_clone,
179+
git_status,
180+
git_log,
181+
git_pull,
182+
git_push,
183+
git_commit,
184+
git_add,
185+
git_get_repo_root,
186+
]

jupyter_ai_tools/toolkits/notebook.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from typing import Any, Dict, Literal, Optional, Tuple
77

88
import nbformat
9-
from jupyter_ai.tools.models import Tool, Toolkit
109
from jupyter_ydoc import YNotebook
1110
from pycrdt import Assoc, Text
1211

@@ -1006,15 +1005,13 @@ async def create_notebook(file_path: str) -> str:
10061005
return f"Error: Failed to create notebook: {str(e)}"
10071006

10081007

1009-
toolkit = Toolkit(
1010-
name="notebook_toolkit",
1011-
description="Tools for reading and manipulating Jupyter notebooks.",
1012-
)
1013-
toolkit.add_tool(Tool(callable=read_notebook, read=True))
1014-
toolkit.add_tool(Tool(callable=read_cell, read=True))
1015-
toolkit.add_tool(Tool(callable=add_cell, read=True, write=True))
1016-
toolkit.add_tool(Tool(callable=insert_cell, read=True, write=True))
1017-
toolkit.add_tool(Tool(callable=delete_cell, delete=True))
1018-
toolkit.add_tool(Tool(callable=edit_cell, read=True, write=True))
1019-
toolkit.add_tool(Tool(callable=get_cell_id_from_index, read=True))
1020-
toolkit.add_tool(Tool(callable=create_notebook, write=True))
1008+
toolkit = [
1009+
read_notebook,
1010+
read_cell,
1011+
add_cell,
1012+
insert_cell,
1013+
delete_cell,
1014+
edit_cell,
1015+
get_cell_id_from_index,
1016+
create_notebook,
1017+
]

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ classifiers = [
2323
dependencies = [
2424
"jupyter_server>=1.6,<3",
2525
"jupyterlab_git",
26-
"jupyter_ai>=3.0.0-beta.1"
26+
"jupyter_server_documents>=0.1.a8"
2727
]
2828

2929

0 commit comments

Comments
 (0)