|
| 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 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) A JSON array containing cell definitions. The structure depends on the action: |
| 13 | + - For insert_cells: Array of objects with properties: |
| 14 | + - content: (required) The cell content |
| 15 | + - cell_type: (optional) The type of cell, either "code" or "markdown" |
| 16 | + - language_id: (optional) The language of the cell (e.g., "python", "javascript") |
| 17 | + - For modify_cell_content: Array of objects with properties: |
| 18 | + - index: (required) The index of the cell to modify (0-based) |
| 19 | + - content: (required) The new content for the cell |
| 20 | + - For replace_cells: A single object with properties: |
| 21 | + - start_index: (required) The starting index of the range to replace (0-based, inclusive) |
| 22 | + - end_index: (required) The ending index of the range to replace (0-based, exclusive) |
| 23 | + - cells: (required) Array of objects with properties: |
| 24 | + - content: (required) The cell content |
| 25 | + - cell_type: (optional) The type of cell, either "code" or "markdown" |
| 26 | + - language_id: (optional) The language of the cell (e.g., "python", "javascript") |
| 27 | + - For delete_cells: A single object with properties: |
| 28 | + - start_index: (required) The starting index of the range to delete (0-based, inclusive) |
| 29 | + - end_index: (required) The ending index of the range to delete (0-based, exclusive) |
| 30 | +- insert_at_index: (optional, only for insert_cells action) The position to insert cells at (0-based, defaults to end of notebook) |
| 31 | +- noexec: (optional) Boolean value to prevent automatic execution of new/modified code cells. |
| 32 | +Usage: |
| 33 | +<notebook_edit> |
| 34 | +<action>action name here</action> |
| 35 | +<cells>[JSON array of cell definitions]</cells> |
| 36 | +<insert_at_index>index value here (if required)</insert_at_index> |
| 37 | +<noexec>true</noexec> |
| 38 | +</notebook_edit> |
| 39 | +
|
| 40 | +Example 1: Insert multiple cells at index 0 |
| 41 | +<notebook_edit> |
| 42 | +<action>insert_cells</action> |
| 43 | +<insert_at_index>0</insert_at_index> |
| 44 | +<cells>[ |
| 45 | + { |
| 46 | + "cell_type": "markdown", |
| 47 | + "content": "# Data Analysis\nThis notebook contains the analysis of our dataset." |
| 48 | + }, |
| 49 | + { |
| 50 | + "cell_type": "code", |
| 51 | + "language_id": "python", |
| 52 | + "content": "import pandas as pd\nimport numpy as np\ndf = pd.read_csv('data.csv')\ndf.head()" |
| 53 | + } |
| 54 | +]</cells> |
| 55 | +</notebook_edit> |
| 56 | +
|
| 57 | +Example 2: Append a new markdown cell (no insert_at_index specified) |
| 58 | +<notebook_edit> |
| 59 | +<action>insert_cells</action> |
| 60 | +<cells>[ |
| 61 | + { |
| 62 | + "cell_type": "markdown", |
| 63 | + "content": "# Data Analysis\nThis notebook contains the analysis of our dataset with the following steps:\n1. Data loading and cleaning\n2. Exploratory data analysis\n3. Statistical testing\n4. Visualization" |
| 64 | + } |
| 65 | +]</cells> |
| 66 | +</notebook_edit> |
| 67 | +
|
| 68 | +Example 3: Modify multiple existing cells without execution |
| 69 | +<notebook_edit> |
| 70 | +<action>modify_cell_content</action> |
| 71 | +<cells>[ |
| 72 | + { |
| 73 | + "index": 2, |
| 74 | + "content": "import matplotlib.pyplot as plt\nplt.figure(figsize=(10, 6))\nplt.plot(df['x'], df['y'])\nplt.title('Data Visualization')\nplt.xlabel('X Axis')\nplt.ylabel('Y Axis')\nplt.show()" |
| 75 | + }, |
| 76 | + { |
| 77 | + "index": 3, |
| 78 | + "content": "# Statistical Analysis\nLet's analyze the correlation between variables." |
| 79 | + } |
| 80 | +]</cells> |
| 81 | +<noexec>true</noexec> |
| 82 | +</notebook_edit> |
| 83 | +
|
| 84 | +Example 4: Replace a range of cells with new cells |
| 85 | +<notebook_edit> |
| 86 | +<action>replace_cells</action> |
| 87 | +<cells>{ |
| 88 | + "start_index": 2, |
| 89 | + "end_index": 4, |
| 90 | + "cells": [ |
| 91 | + { |
| 92 | + "cell_type": "code", |
| 93 | + "language_id": "python", |
| 94 | + "content": "import matplotlib.pyplot as plt\nimport seaborn as sns\n\nplt.figure(figsize=(10, 6))\nsns.scatterplot(x='x', y='y', data=df)\nplt.title('Scatter Plot')\nplt.show()" |
| 95 | + }, |
| 96 | + { |
| 97 | + "cell_type": "markdown", |
| 98 | + "content": "## Observations\nThe scatter plot shows a positive correlation between x and y variables." |
| 99 | + } |
| 100 | + ] |
| 101 | +}</cells> |
| 102 | +</notebook_edit> |
| 103 | +
|
| 104 | +Example 5: Delete a range of cells |
| 105 | +<notebook_edit> |
| 106 | +<action>delete_cells</action> |
| 107 | +<cells>{ |
| 108 | + "start_index": 2, |
| 109 | + "end_index": 4 |
| 110 | +}</cells> |
| 111 | +</notebook_edit>` |
| 112 | +} |
0 commit comments