Skip to content

Commit 55d90cf

Browse files
committed
Update the default tool to create a notebook
1 parent 7f8ba57 commit 55d90cf

File tree

3 files changed

+39
-19
lines changed

3 files changed

+39
-19
lines changed

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { AIProviderRegistry } from './provider';
2929
import { aiSettingsRenderer, textArea } from './settings';
3030
import { IAIProviderRegistry, IToolRegistry, PLUGIN_IDS } from './tokens';
3131
import { ToolsRegistry } from './tool-registry';
32-
import { testTool } from './tools/test-tool';
32+
import { createNotebook } from './tools/create-notebook';
3333

3434
const chatCommandRegistryPlugin: JupyterFrontEndPlugin<IChatCommandRegistry> = {
3535
id: PLUGIN_IDS.chatCommandRegistry,
@@ -313,7 +313,7 @@ const toolRegistryPlugin: JupyterFrontEndPlugin<IToolRegistry> = {
313313
provides: IToolRegistry,
314314
activate: (app: JupyterFrontEnd): IToolRegistry => {
315315
const registry = new ToolsRegistry();
316-
registry.add(testTool);
316+
registry.add(createNotebook(app.commands));
317317
return registry;
318318
}
319319
};

src/tools/create-notebook.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { StructuredToolInterface, tool } from '@langchain/core/tools';
2+
import { CommandRegistry } from '@lumino/commands';
3+
import { ReadonlyPartialJSONObject } from '@lumino/coreutils';
4+
import { z } from 'zod';
5+
6+
export const createNotebook = (
7+
commands: CommandRegistry
8+
): StructuredToolInterface => {
9+
return tool(
10+
async ({ command, args }) => {
11+
let result: any = 'No command called';
12+
if (command === 'notebook:create-new') {
13+
result = await commands.execute(
14+
command,
15+
args as ReadonlyPartialJSONObject
16+
);
17+
}
18+
const output = `
19+
The test tool has been called, with the following query: "${command}"
20+
The args for the commands where ${JSON.stringify(args)}
21+
The result of the command (if called) is "${result}"
22+
`;
23+
return output;
24+
},
25+
{
26+
name: 'createNotebook',
27+
description: 'Run jupyterlab command to create a notebook',
28+
schema: z.object({
29+
command: z.string().describe('The Jupyterlab command id to execute'),
30+
args: z
31+
.object({})
32+
.passthrough()
33+
.describe('The argument for the command')
34+
})
35+
}
36+
);
37+
};

src/tools/test-tool.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)