1
1
import * as gptscript from "../src/gptscript"
2
+ import { ArgumentSchemaType , PropertyType , ToolType } from "../src/gptscript"
2
3
import path from "path"
3
4
import { fileURLToPath } from "url"
4
5
@@ -45,7 +46,7 @@ describe("gptscript module", () => {
45
46
instructions : "who was the president of the united states in 1928?"
46
47
}
47
48
48
- const run = await g . evaluate ( t as any )
49
+ const run = await g . evaluate ( t )
49
50
expect ( run ) . toBeDefined ( )
50
51
expect ( await run . text ( ) ) . toContain ( "Calvin Coolidge" )
51
52
} )
@@ -60,7 +61,7 @@ describe("gptscript module", () => {
60
61
disableCache : true ,
61
62
}
62
63
63
- const run = await g . evaluate ( t as any , opts )
64
+ const run = await g . evaluate ( t , opts )
64
65
run . on ( gptscript . RunEventType . CallProgress , ( data : gptscript . CallFrame ) => {
65
66
for ( let output of data . output ) out += `system: ${ output . content } `
66
67
} )
@@ -80,7 +81,7 @@ describe("gptscript module", () => {
80
81
context : [ path . join ( __dirname , "fixtures" , "acorn-labs-context.gpt" ) ]
81
82
}
82
83
83
- const run = await g . evaluate ( t as any , { disableCache : true } )
84
+ const run = await g . evaluate ( t , { disableCache : true } )
84
85
out = await run . text ( )
85
86
err = run . err
86
87
@@ -167,13 +168,18 @@ describe("gptscript module", () => {
167
168
name : "ask" ,
168
169
description : "This tool is used to ask a question" ,
169
170
arguments : {
170
- type : "object" ,
171
- question : "The question to ask"
171
+ type : ArgumentSchemaType ,
172
+ properties : {
173
+ question : {
174
+ type : PropertyType ,
175
+ description : "The question to ask" ,
176
+ }
177
+ }
172
178
} ,
173
179
instructions : "${question}"
174
180
}
175
181
176
- const response = await ( await g . evaluate ( [ t0 as any , t1 as any ] ) ) . text ( )
182
+ const response = await ( await g . evaluate ( [ t0 , t1 ] ) ) . text ( )
177
183
expect ( response ) . toBeDefined ( )
178
184
expect ( response ) . toContain ( "Calvin Coolidge" )
179
185
} , 30000 )
@@ -182,11 +188,11 @@ describe("gptscript module", () => {
182
188
const t0 = {
183
189
tools : [ "ask" ] ,
184
190
instructions : "Only use the ask tool to ask who was the president of the united states in 1928?"
185
- } as any
191
+ }
186
192
const t1 = {
187
193
name : "other" ,
188
194
instructions : "Who was the president of the united states in 1986?"
189
- } as any
195
+ }
190
196
const t2 = {
191
197
name : "ask" ,
192
198
description : "This tool is used to ask a question" ,
@@ -195,7 +201,7 @@ describe("gptscript module", () => {
195
201
question : "The question to ask"
196
202
} ,
197
203
instructions : "${question}"
198
- } as any
204
+ }
199
205
200
206
const response = await ( await g . evaluate ( [ t0 , t1 , t2 ] , { subTool : "other" } ) ) . text ( )
201
207
expect ( response ) . toBeDefined ( )
@@ -246,21 +252,22 @@ describe("gptscript module", () => {
246
252
247
253
test ( "format tool" , async ( ) => {
248
254
const tool = {
249
- type : "tool" ,
255
+ id : "my-tool" ,
256
+ type : ToolType ,
250
257
tools : [ "sys.write" , "sys.read" ] ,
251
258
instructions : "This is a test" ,
252
259
arguments : {
253
- type : "object" ,
260
+ type : ArgumentSchemaType ,
254
261
properties : {
255
262
text : {
256
- type : "string" ,
263
+ type : PropertyType ,
257
264
description : "The text to write"
258
265
}
259
266
}
260
267
}
261
268
}
262
269
263
- const response = await g . stringify ( [ tool as any ] )
270
+ const response = await g . stringify ( [ tool ] )
264
271
expect ( response ) . toBeDefined ( )
265
272
expect ( response ) . toContain ( "Tools: sys.write, sys.read" )
266
273
expect ( response ) . toContain ( "This is a test" )
@@ -277,7 +284,7 @@ describe("gptscript module", () => {
277
284
const opts = {
278
285
disableCache : true ,
279
286
}
280
- let run = await g . evaluate ( t as any , opts )
287
+ let run = await g . evaluate ( t , opts )
281
288
282
289
const inputs = [
283
290
"List the three largest states in the United States by area." ,
@@ -375,14 +382,14 @@ describe("gptscript module", () => {
375
382
instructions : "You are a chat bot. Don't finish the conversation until I say 'bye'." ,
376
383
tools : [ "sys.chat.finish" ]
377
384
}
378
- let run = await g . evaluate ( t as any , { disableCache : true } )
385
+ let run = await g . evaluate ( t , { disableCache : true } )
379
386
380
387
run = run . nextChat ( "List the three largest states in the United States by area." )
381
388
expect ( await run . text ( ) ) . toContain ( "California" )
382
389
expect ( run . err ) . toEqual ( "" )
383
390
expect ( run . state ) . toEqual ( gptscript . RunState . Continue )
384
391
385
- run = await g . evaluate ( t as any , {
392
+ run = await g . evaluate ( t , {
386
393
disableCache : true ,
387
394
input : "What is the capital of the second one?" ,
388
395
chatState : run . currentChatState ( )
@@ -399,7 +406,7 @@ describe("gptscript module", () => {
399
406
instructions : "List the files in the current working directory." ,
400
407
tools : [ "sys.exec" ]
401
408
}
402
- const run = await g . evaluate ( t as any , { confirm : true } )
409
+ const run = await g . evaluate ( t , { confirm : true } )
403
410
run . on ( gptscript . RunEventType . CallConfirm , async ( data : gptscript . CallFrame ) => {
404
411
expect ( data . input ) . toContain ( `"ls"` )
405
412
confirmFound = true
@@ -417,7 +424,7 @@ describe("gptscript module", () => {
417
424
instructions : "List the files in the current working directory." ,
418
425
tools : [ "sys.exec" ]
419
426
}
420
- const run = await g . evaluate ( t as any , { confirm : true } )
427
+ const run = await g . evaluate ( t , { confirm : true } )
421
428
run . on ( gptscript . RunEventType . CallConfirm , async ( data : gptscript . CallFrame ) => {
422
429
expect ( data . input ) . toContain ( `"ls"` )
423
430
confirmFound = true
@@ -435,7 +442,7 @@ describe("gptscript module", () => {
435
442
instructions : "Use the sys.prompt user to ask the user for 'first name' which is not sensitive. After you get their first name, say hello." ,
436
443
tools : [ "sys.prompt" ]
437
444
}
438
- const run = await g . evaluate ( t as any , { prompt : true } )
445
+ const run = await g . evaluate ( t , { prompt : true } )
439
446
run . on ( gptscript . RunEventType . Prompt , async ( data : gptscript . PromptFrame ) => {
440
447
expect ( data . message ) . toContain ( "first name" )
441
448
expect ( data . fields . length ) . toEqual ( 1 )
@@ -457,7 +464,7 @@ describe("gptscript module", () => {
457
464
instructions : "Use the sys.prompt user to ask the user for 'first name' which is not sensitive. After you get their first name, say hello." ,
458
465
tools : [ "sys.prompt" ]
459
466
}
460
- const run = await g . evaluate ( t as any )
467
+ const run = await g . evaluate ( t )
461
468
run . on ( gptscript . RunEventType . Prompt , async ( data : gptscript . PromptFrame ) => {
462
469
promptFound = true
463
470
} )
0 commit comments