File tree Expand file tree Collapse file tree 3 files changed +39
-19
lines changed Expand file tree Collapse file tree 3 files changed +39
-19
lines changed Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ import { AIProviderRegistry } from './provider';
29
29
import { aiSettingsRenderer , textArea } from './settings' ;
30
30
import { IAIProviderRegistry , IToolRegistry , PLUGIN_IDS } from './tokens' ;
31
31
import { ToolsRegistry } from './tool-registry' ;
32
- import { testTool } from './tools/test-tool ' ;
32
+ import { createNotebook } from './tools/create-notebook ' ;
33
33
34
34
const chatCommandRegistryPlugin : JupyterFrontEndPlugin < IChatCommandRegistry > = {
35
35
id : PLUGIN_IDS . chatCommandRegistry ,
@@ -313,7 +313,7 @@ const toolRegistryPlugin: JupyterFrontEndPlugin<IToolRegistry> = {
313
313
provides : IToolRegistry ,
314
314
activate : ( app : JupyterFrontEnd ) : IToolRegistry => {
315
315
const registry = new ToolsRegistry ( ) ;
316
- registry . add ( testTool ) ;
316
+ registry . add ( createNotebook ( app . commands ) ) ;
317
317
return registry ;
318
318
}
319
319
} ;
Original file line number Diff line number Diff line change
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
+ } ;
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments