@@ -2,6 +2,7 @@ import * as gptscript from "../src/gptscript"
22import { ArgumentSchemaType , getEnv , PropertyType , RunEventType , TextType , ToolType } from "../src/gptscript"
33import path from "path"
44import { fileURLToPath } from "url"
5+ import * as fs from "node:fs"
56
67let gFirst : gptscript . GPTScript
78let g : gptscript . GPTScript
@@ -286,6 +287,7 @@ describe("gptscript module", () => {
286287 await g . parse ( path . join ( __dirname , "fixtures" , "non-existent.gpt" ) )
287288 } catch ( e ) {
288289 expect ( e ) . toBeDefined ( )
290+ expect ( typeof e !== "string" ) . toBeTruthy ( )
289291 return
290292 }
291293 expect ( false ) . toBeTruthy ( )
@@ -296,6 +298,7 @@ describe("gptscript module", () => {
296298 await g . parse ( "github.com/thedadams/dne" )
297299 } catch ( e ) {
298300 expect ( e ) . toBeDefined ( )
301+ expect ( typeof e !== "string" ) . toBeTruthy ( )
299302 return
300303 }
301304 expect ( false ) . toBeTruthy ( )
@@ -408,6 +411,58 @@ describe("gptscript module", () => {
408411 expect ( response ) . toContain ( "Type: Context" )
409412 } )
410413
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+ expect ( response . program . name ) . toBeTruthy ( )
435+ expect ( response . program . entryToolId ) . toBeTruthy ( )
436+ expect ( response . program . toolSet ) . toBeDefined ( )
437+ } , 30000 )
438+
439+ test ( "load tools" , async ( ) => {
440+ const tools = [ {
441+ tools : [ "ask" ] ,
442+ instructions : "Only use the ask tool to ask who was the president of the united states in 1928?"
443+ } ,
444+ {
445+ name : "other" ,
446+ instructions : "Who was the president of the united states in 1986?"
447+ } ,
448+ {
449+ name : "ask" ,
450+ description : "This tool is used to ask a question" ,
451+ arguments : {
452+ type : "object" ,
453+ question : "The question to ask"
454+ } ,
455+ instructions : "${question}"
456+ } ,
457+ ] as gptscript . ToolDef [ ]
458+ const response = await g . loadTools ( tools )
459+ expect ( response . program ) . toBeDefined ( )
460+ // Name will not be defined in this case.
461+ expect ( response . program . name ) . toBeFalsy ( )
462+ expect ( response . program . entryToolId ) . toBeTruthy ( )
463+ expect ( response . program . toolSet ) . toBeDefined ( )
464+ } , 30000 )
465+
411466 test ( "exec tool with chat" , async ( ) => {
412467 let err = undefined
413468 const t = {
0 commit comments