|
| 1 | +import { ToolArgs } from "./types" |
| 2 | + |
| 3 | +export function getNotebookEditToolDescription(args: ToolArgs): string { |
| 4 | + return `## notebook_edit |
| 5 | +Description: Edit the active notebook. 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 true. |
| 6 | +Parameters: |
| 7 | +- action: (required) The action to perform. Valid values are: |
| 8 | + - "insert_cells": Insert new cells into the notebook (or append to the end if insert_at_index is omitted) |
| 9 | + - "modify_cell_content": Modify the content of existing cells in the notebook (note: this will clear any existing outputs) |
| 10 | + - "replace_cells": Replace a range of cells with new cells (note: this will clear any existing outputs) |
| 11 | + - "delete_cells": Delete a range of cells from the notebook |
| 12 | +- cells: (required for insert_cells, modify_cell_content, replace_cells) Contains cell definitions using markdown code blocks: |
| 13 | + - For insert_cells: A series of code blocks representing the cells to insert |
| 14 | + - For modify_cell_content: Code blocks with @cell#N tag before each block (where N is the 0-based index) |
| 15 | + - For replace_cells: Series of code blocks to replace the specified range of cells |
| 16 | +- insert_at_index: (optional, only for insert_cells action) The position to insert cells at (0-based, defaults to end of notebook) |
| 17 | +- start_index: (required for replace_cells and delete_cells) The starting index of the range (0-based, inclusive) |
| 18 | +- end_index: (required for replace_cells and delete_cells) The ending index of the range (0-based, exclusive) |
| 19 | +- noexec: (optional) Boolean value to prevent automatic execution of new/modified code cells. |
| 20 | +
|
| 21 | +The language of each cell is determined by the code block header (e.g., \`\`\`python). |
| 22 | +Cells with \`\`\`markdown header are treated as markdown cells, all others are code cells. |
| 23 | +
|
| 24 | +Usage: |
| 25 | +<notebook_edit> |
| 26 | +<action>action name here</action> |
| 27 | +<cells> |
| 28 | +(markdown code blocks for cell content here) |
| 29 | +</cells> |
| 30 | +<insert_at_index>index value here (if required)</insert_at_index> |
| 31 | +<start_index>start index (for replace/delete actions)</start_index> |
| 32 | +<end_index>end index (for replace/delete actions)</end_index> |
| 33 | +<noexec>true</noexec> |
| 34 | +</notebook_edit> |
| 35 | +
|
| 36 | +Example 1: Insert multiple cells at index 0 |
| 37 | +<notebook_edit> |
| 38 | +<action>insert_cells</action> |
| 39 | +<insert_at_index>0</insert_at_index> |
| 40 | +<cells> |
| 41 | +\`\`\`markdown |
| 42 | +# Data Analysis |
| 43 | +This notebook contains the analysis of our dataset. |
| 44 | +\`\`\` |
| 45 | +
|
| 46 | +\`\`\`python |
| 47 | +import pandas as pd |
| 48 | +import numpy as np |
| 49 | +df = pd.read_csv('data.csv') |
| 50 | +df.head() |
| 51 | +\`\`\` |
| 52 | +</cells> |
| 53 | +</notebook_edit> |
| 54 | +
|
| 55 | +Example 2: Append a new markdown cell (no insert_at_index specified) |
| 56 | +<notebook_edit> |
| 57 | +<action>insert_cells</action> |
| 58 | +<cells> |
| 59 | +\`\`\`markdown |
| 60 | +# Data Analysis |
| 61 | +This notebook contains the analysis of our dataset with the following steps: |
| 62 | +1. Data loading and cleaning |
| 63 | +2. Exploratory data analysis |
| 64 | +3. Statistical testing |
| 65 | +4. Visualization |
| 66 | +\`\`\` |
| 67 | +</cells> |
| 68 | +</notebook_edit> |
| 69 | +
|
| 70 | +Example 3: Modify multiple existing cells without execution |
| 71 | +<notebook_edit> |
| 72 | +<action>modify_cell_content</action> |
| 73 | +<cells> |
| 74 | +@cell#2 |
| 75 | +\`\`\`python |
| 76 | +import matplotlib.pyplot as plt |
| 77 | +plt.figure(figsize=(10, 6)) |
| 78 | +plt.plot(df['x'], df['y']) |
| 79 | +plt.title('Data Visualization') |
| 80 | +plt.xlabel('X Axis') |
| 81 | +plt.ylabel('Y Axis') |
| 82 | +plt.show() |
| 83 | +\`\`\` |
| 84 | +
|
| 85 | +@cell#3 |
| 86 | +\`\`\`markdown |
| 87 | +# Statistical Analysis |
| 88 | +Let's analyze the correlation between variables. |
| 89 | +\`\`\` |
| 90 | +</cells> |
| 91 | +<noexec>true</noexec> |
| 92 | +</notebook_edit> |
| 93 | +
|
| 94 | +Example 4: Replace a range of cells with new cells |
| 95 | +<notebook_edit> |
| 96 | +<action>replace_cells</action> |
| 97 | +<start_index>2</start_index> |
| 98 | +<end_index>4</end_index> |
| 99 | +<cells> |
| 100 | +\`\`\`python |
| 101 | +import matplotlib.pyplot as plt |
| 102 | +import seaborn as sns |
| 103 | +
|
| 104 | +plt.figure(figsize=(10, 6)) |
| 105 | +sns.scatterplot(x='x', y='y', data=df) |
| 106 | +plt.title('Scatter Plot') |
| 107 | +plt.show() |
| 108 | +\`\`\` |
| 109 | +
|
| 110 | +\`\`\`markdown |
| 111 | +## Observations |
| 112 | +The scatter plot shows a positive correlation between x and y variables. |
| 113 | +\`\`\` |
| 114 | +</cells> |
| 115 | +</notebook_edit> |
| 116 | +
|
| 117 | +Example 5: Delete a range of cells |
| 118 | +<notebook_edit> |
| 119 | +<action>delete_cells</action> |
| 120 | +<start_index>2</start_index> |
| 121 | +<end_index>4</end_index> |
| 122 | +<cells> |
| 123 | +</cells> |
| 124 | +</notebook_edit> |
| 125 | +
|
| 126 | +Notes: |
| 127 | +- The user must have opened a notebook file in VSCode to have an active notebook in the workspace |
| 128 | +- If no active notebook is found, an error message will be returned |
| 129 | +- Cell indices are 0-based (the first cell is at index 0) |
| 130 | +- For modify_cell_content, each code block must have a @cell#N tag to identify which cell to modify` |
| 131 | +} |
0 commit comments