@@ -2,6 +2,7 @@ import * as gptscript from "../src/gptscript"
2
2
import { ArgumentSchemaType , getEnv , PropertyType , RunEventType , TextType , ToolType } from "../src/gptscript"
3
3
import path from "path"
4
4
import { fileURLToPath } from "url"
5
+ import * as fs from "node:fs"
5
6
6
7
let gFirst : gptscript . GPTScript
7
8
let g : gptscript . GPTScript
@@ -286,6 +287,7 @@ describe("gptscript module", () => {
286
287
await g . parse ( path . join ( __dirname , "fixtures" , "non-existent.gpt" ) )
287
288
} catch ( e ) {
288
289
expect ( e ) . toBeDefined ( )
290
+ expect ( typeof e !== "string" ) . toBeTruthy ( )
289
291
return
290
292
}
291
293
expect ( false ) . toBeTruthy ( )
@@ -296,6 +298,7 @@ describe("gptscript module", () => {
296
298
await g . parse ( "github.com/thedadams/dne" )
297
299
} catch ( e ) {
298
300
expect ( e ) . toBeDefined ( )
301
+ expect ( typeof e !== "string" ) . toBeTruthy ( )
299
302
return
300
303
}
301
304
expect ( false ) . toBeTruthy ( )
@@ -408,6 +411,59 @@ describe("gptscript module", () => {
408
411
expect ( response ) . toContain ( "Type: Context" )
409
412
} )
410
413
414
+ test ( "load simple file" , async ( ) => {
415
+ const response = await g . load ( path . join ( __dirname , "fixtures" , "test.gpt" ) )
416
+ expect ( response . program ) . toBeDefined ( )
417
+ expect ( response . program . name ) . toBeTruthy ( )
418
+ expect ( response . program . entryToolId ) . toBeTruthy ( )
419
+ expect ( response . program . toolSet ) . toBeDefined ( )
420
+ } , 30000 )
421
+
422
+ test ( "load remote tool" , async ( ) => {
423
+ const response = await g . load ( "github.com/gptscript-ai/context/workspace" )
424
+ expect ( response . program ) . toBeDefined ( )
425
+ expect ( response . program . name ) . toBeTruthy ( )
426
+ expect ( response . program . entryToolId ) . toBeTruthy ( )
427
+ expect ( response . program . toolSet ) . toBeDefined ( )
428
+ } , 30000 )
429
+
430
+ test ( "load content" , async ( ) => {
431
+ const content = fs . readFileSync ( path . join ( __dirname , "fixtures" , "test.gpt" ) , { encoding : "utf8" } )
432
+ const response = await g . loadContent ( content )
433
+ expect ( response . program ) . toBeDefined ( )
434
+ // Name will not be defined in this case.
435
+ expect ( response . program . name ) . toBeFalsy ( )
436
+ expect ( response . program . entryToolId ) . toBeTruthy ( )
437
+ expect ( response . program . toolSet ) . toBeDefined ( )
438
+ } , 30000 )
439
+
440
+ test ( "load tools" , async ( ) => {
441
+ const tools = [ {
442
+ tools : [ "ask" ] ,
443
+ instructions : "Only use the ask tool to ask who was the president of the united states in 1928?"
444
+ } ,
445
+ {
446
+ name : "other" ,
447
+ instructions : "Who was the president of the united states in 1986?"
448
+ } ,
449
+ {
450
+ name : "ask" ,
451
+ description : "This tool is used to ask a question" ,
452
+ arguments : {
453
+ type : "object" ,
454
+ question : "The question to ask"
455
+ } ,
456
+ instructions : "${question}"
457
+ } ,
458
+ ] as gptscript . ToolDef [ ]
459
+ const response = await g . loadTools ( tools )
460
+ expect ( response . program ) . toBeDefined ( )
461
+ // Name will not be defined in this case.
462
+ expect ( response . program . name ) . toBeFalsy ( )
463
+ expect ( response . program . entryToolId ) . toBeTruthy ( )
464
+ expect ( response . program . toolSet ) . toBeDefined ( )
465
+ } , 30000 )
466
+
411
467
test ( "exec tool with chat" , async ( ) => {
412
468
let err = undefined
413
469
const t = {
0 commit comments