|
| 1 | +import { ToolArgs } from "./types" |
| 2 | + |
| 3 | +export function getNotebookEditToolDescription(args: ToolArgs): string { |
| 4 | + return `## notebook_edit |
| 5 | +Description: Edit the active notebook in the editor. This tool allows you to insert new cells, append cells to the end, or replace existing cells. Note that new/modified code cells will be executed immediately by default, unless the <noexec/> parameter is present. |
| 6 | +Parameters: |
| 7 | +- action: (required) The action to perform. Valid values are: |
| 8 | + - "insert_cells": Insert a new cell into the notebook (or append to the end if cell_index is omitted) |
| 9 | + - "modify_cell_content": Modify the content of an existing cell in the notebook (note: this will clear any existing outputs) |
| 10 | + - "replace_cells": Replace a range of cells with a new cell (note: this will clear any existing outputs) |
| 11 | +- cell_index: (required for modify_cell_content, optional for insert_cells) The index of the cell to modify (0-based), or for insert_cells the position to insert at (defaults to end of notebook for append) |
| 12 | +- start_index: (required for replace_cells) The starting index of the range to replace (0-based, inclusive) |
| 13 | +- end_index: (required for replace_cells) The ending index of the range to replace (0-based, exclusive) |
| 14 | +- cell_type: (optional for insert_cells and replace_cells) The type of cell, either "code" or "markdown" |
| 15 | +- language_id: (optional for insert_cells and replace_cells) The language of the cell (e.g., "python", "javascript") |
| 16 | +- cell_content: (required for all actions) The content of the cell |
| 17 | +- noexec: (optional) Can be used as a flag <noexec/> or with explicit value <noexec>true</noexec> to prevent automatic execution of new/modified code cells. |
| 18 | +Usage: |
| 19 | +<notebook_edit> |
| 20 | +<action>action name here</action> |
| 21 | +<cell_index>index value here (if required)</cell_index> |
| 22 | +<start_index>start index here (if required)</start_index> |
| 23 | +<end_index>end index here (if required)</end_index> |
| 24 | +<cell_type>cell type here (if required)</cell_type> |
| 25 | +<language_id>language here (if required)</language_id> |
| 26 | +<cell_content>cell content here</cell_content> |
| 27 | +<noexec/> |
| 28 | +</notebook_edit> |
| 29 | +
|
| 30 | +Example 1: Insert a new Python code cell |
| 31 | +<notebook_edit> |
| 32 | +<action>insert_cells</action> |
| 33 | +<cell_index>0</cell_index> |
| 34 | +<cell_type>code</cell_type> |
| 35 | +<language_id>python</language_id> |
| 36 | +<cell_content>import pandas as pd |
| 37 | +import numpy as np |
| 38 | +df = pd.read_csv('data.csv') |
| 39 | +df.head()</cell_content> |
| 40 | +</notebook_edit> |
| 41 | +
|
| 42 | +Example 2: Append a new markdown cell |
| 43 | +<notebook_edit> |
| 44 | +<action>insert_cells</action> |
| 45 | +<cell_type>markdown</cell_type> |
| 46 | +<cell_content># Data Analysis |
| 47 | +This notebook contains the analysis of our dataset with the following steps: |
| 48 | +1. Data loading and cleaning |
| 49 | +2. Exploratory data analysis |
| 50 | +3. Statistical testing |
| 51 | +4. Visualization</cell_content> |
| 52 | +</notebook_edit> |
| 53 | +
|
| 54 | +Example 3: Modify an existing cell without execution |
| 55 | +<notebook_edit> |
| 56 | +<action>modify_cell_content</action> |
| 57 | +<cell_index>2</cell_index> |
| 58 | +<noexec/> |
| 59 | +<cell_content>import matplotlib.pyplot as plt |
| 60 | +plt.figure(figsize=(10, 6)) |
| 61 | +plt.plot(df['x'], df['y']) |
| 62 | +plt.title('Data Visualization') |
| 63 | +plt.xlabel('X Axis') |
| 64 | +plt.ylabel('Y Axis') |
| 65 | +plt.show()</cell_content> |
| 66 | +</notebook_edit> |
| 67 | +
|
| 68 | +Example 4: Replace a range of cells with a new cell |
| 69 | +<notebook_edit> |
| 70 | +<action>replace_cells</action> |
| 71 | +<start_index>2</start_index> |
| 72 | +<end_index>4</end_index> |
| 73 | +<cell_type>code</cell_type> |
| 74 | +<language_id>python</language_id> |
| 75 | +<cell_content>import matplotlib.pyplot as plt |
| 76 | +import seaborn as sns |
| 77 | +
|
| 78 | +plt.figure(figsize=(10, 6)) |
| 79 | +sns.scatterplot(x='x', y='y', data=df) |
| 80 | +plt.title('Scatter Plot') |
| 81 | +plt.show()</cell_content> |
| 82 | +</notebook_edit> |
| 83 | +
|
| 84 | +IMPORTANT: For insert_cells and replace_cells, each cell_content tag creates a new cell. The cell_type and language_id tags must come BEFORE the cell_content tag they apply to. The last cell_type before a cell_content will be used as that cell's type, and the last language_id before a cell_content will be used as that cell's language.` |
| 85 | +} |
0 commit comments