|
| 1 | +"""JupyterLab Commands toolkit for Jupyter AI""" |
| 2 | +from jupyter_ai.tools.models import Tool, Toolkit |
| 3 | + |
| 4 | +from typing import Optional |
| 5 | +from .tools import ( |
| 6 | + open_document, |
| 7 | + open_markdown_file_in_preview_mode, |
| 8 | + clear_all_outputs_in_notebook, |
| 9 | + show_diff_of_current_notebook, |
| 10 | + INSERT_MODE |
| 11 | +) |
| 12 | + |
| 13 | +# Create the toolkit |
| 14 | +toolkit = Toolkit( |
| 15 | + name="jupyterlab_commands_toolkit", |
| 16 | + description="""A comprehensive toolkit for controlling JupyterLab interface and performing notebook operations through AI commands. |
| 17 | +
|
| 18 | +This toolkit provides programmatic access to JupyterLab's core functionality, enabling AI assistants to: |
| 19 | +
|
| 20 | +**Document Management:** |
| 21 | +- Open files, notebooks, and documents with precise control over layout positioning |
| 22 | +- Support for split-pane layouts (top, left, right, bottom) and tab management |
| 23 | +- Open markdown files in rendered preview mode for better readability |
| 24 | +
|
| 25 | +**Notebook Operations:** |
| 26 | +- Clear all cell outputs in the active notebook for cleanup and sharing |
| 27 | +- Display git diffs for notebooks using nbdime visualization |
| 28 | +- Maintain notebook structure while performing operations |
| 29 | +
|
| 30 | +**Layout Control:** |
| 31 | +- Split current workspace into multiple panes |
| 32 | +- Merge content with adjacent areas |
| 33 | +- Create new tabs before or after current position |
| 34 | +- Flexible positioning options for optimal workspace organization |
| 35 | +
|
| 36 | +**Key Features:** |
| 37 | +- Event-driven architecture using JupyterLab's command system |
| 38 | +- Seamless integration with Jupyter AI for natural language control |
| 39 | +- Support for relative file paths from server root directory |
| 40 | +- Comprehensive error handling and user feedback |
| 41 | +- Compatible with JupyterLab 4.0+ and modern Jupyter environments |
| 42 | +
|
| 43 | +Use these tools to programmatically manage your JupyterLab workspace, organize documents, and perform common notebook operations through conversational AI interfaces.""" |
| 44 | +) |
| 45 | + |
| 46 | +# Add tools to the toolkit |
| 47 | +toolkit.add_tool(Tool(callable=open_document, read=True)) |
| 48 | +toolkit.add_tool(Tool(callable=open_markdown_file_in_preview_mode, read=True)) |
| 49 | +toolkit.add_tool(Tool(callable=clear_all_outputs_in_notebook, read=True)) |
| 50 | +toolkit.add_tool(Tool(callable=show_diff_of_current_notebook, read=True)) |
0 commit comments