@@ -498,7 +498,7 @@ func TestParseFileWithMetadata(t *testing.T) {
498
498
}
499
499
500
500
func TestParseTool (t * testing.T ) {
501
- tools , err := g .ParseTool (context .Background (), "echo hello" )
501
+ tools , err := g .ParseContent (context .Background (), "echo hello" )
502
502
if err != nil {
503
503
t .Errorf ("Error parsing tool: %v" , err )
504
504
}
@@ -517,7 +517,7 @@ func TestParseTool(t *testing.T) {
517
517
}
518
518
519
519
func TestEmptyParseTool (t * testing.T ) {
520
- tools , err := g .ParseTool (context .Background (), "" )
520
+ tools , err := g .ParseContent (context .Background (), "" )
521
521
if err != nil {
522
522
t .Errorf ("Error parsing tool: %v" , err )
523
523
}
@@ -528,7 +528,7 @@ func TestEmptyParseTool(t *testing.T) {
528
528
}
529
529
530
530
func TestParseToolWithTextNode (t * testing.T ) {
531
- tools , err := g .ParseTool (context .Background (), "echo hello\n ---\n !markdown\n hello" )
531
+ tools , err := g .ParseContent (context .Background (), "echo hello\n ---\n !markdown\n hello" )
532
532
if err != nil {
533
533
t .Errorf ("Error parsing tool: %v" , err )
534
534
}
@@ -735,8 +735,8 @@ func TestFileChat(t *testing.T) {
735
735
}
736
736
inputs := []string {
737
737
"List the 3 largest of the Great Lakes by volume." ,
738
- "What is the volume of the second in the list in cubic miles?" ,
739
- "What is the total area of the third in the list in square miles?" ,
738
+ "For the second one in the list: what is the volume cubic miles?" ,
739
+ "For the third one in the list: what is the total area in square miles?" ,
740
740
}
741
741
742
742
expectedOutputs := []string {
@@ -1220,3 +1220,115 @@ func TestParseThenEvaluateWithMetadata(t *testing.T) {
1220
1220
t .Errorf ("Unexpected output: %s" , out )
1221
1221
}
1222
1222
}
1223
+
1224
+ func TestLoadFile (t * testing.T ) {
1225
+ wd , err := os .Getwd ()
1226
+ if err != nil {
1227
+ t .Fatalf ("Error getting working directory: %v" , err )
1228
+ }
1229
+
1230
+ prg , err := g .LoadFile (context .Background (), wd + "/test/global-tools.gpt" )
1231
+ if err != nil {
1232
+ t .Fatalf ("Error loading file: %v" , err )
1233
+ }
1234
+
1235
+ if prg .EntryToolID == "" {
1236
+ t .Errorf ("Unexpected entry tool ID: %s" , prg .EntryToolID )
1237
+ }
1238
+
1239
+ if len (prg .ToolSet ) == 0 {
1240
+ t .Errorf ("Unexpected number of tools: %d" , len (prg .ToolSet ))
1241
+ }
1242
+
1243
+ if prg .Name == "" {
1244
+ t .Errorf ("Unexpected name: %s" , prg .Name )
1245
+ }
1246
+ }
1247
+
1248
+ func TestLoadRemoteFile (t * testing.T ) {
1249
+ prg , err := g .LoadFile (context .Background (), "github.com/gptscript-ai/context/workspace" )
1250
+ if err != nil {
1251
+ t .Fatalf ("Error loading file: %v" , err )
1252
+ }
1253
+
1254
+ if prg .EntryToolID == "" {
1255
+ t .Errorf ("Unexpected entry tool ID: %s" , prg .EntryToolID )
1256
+ }
1257
+
1258
+ if len (prg .ToolSet ) == 0 {
1259
+ t .Errorf ("Unexpected number of tools: %d" , len (prg .ToolSet ))
1260
+ }
1261
+
1262
+ if prg .Name == "" {
1263
+ t .Errorf ("Unexpected name: %s" , prg .Name )
1264
+ }
1265
+ }
1266
+
1267
+ func TestLoadContent (t * testing.T ) {
1268
+ wd , err := os .Getwd ()
1269
+ if err != nil {
1270
+ t .Fatalf ("Error getting working directory: %v" , err )
1271
+ }
1272
+
1273
+ content , err := os .ReadFile (wd + "/test/global-tools.gpt" )
1274
+ if err != nil {
1275
+ t .Fatalf ("Error reading file: %v" , err )
1276
+ }
1277
+
1278
+ prg , err := g .LoadContent (context .Background (), string (content ))
1279
+ if err != nil {
1280
+ t .Fatalf ("Error loading file: %v" , err )
1281
+ }
1282
+
1283
+ if prg .EntryToolID == "" {
1284
+ t .Errorf ("Unexpected entry tool ID: %s" , prg .EntryToolID )
1285
+ }
1286
+
1287
+ if len (prg .ToolSet ) == 0 {
1288
+ t .Errorf ("Unexpected number of tools: %d" , len (prg .ToolSet ))
1289
+ }
1290
+
1291
+ // Name won't be set in this case
1292
+ if prg .Name != "" {
1293
+ t .Errorf ("Unexpected name: %s" , prg .Name )
1294
+ }
1295
+ }
1296
+
1297
+ func TestLoadTools (t * testing.T ) {
1298
+ tools := []ToolDef {
1299
+ {
1300
+ Tools : []string {"echo" },
1301
+ Instructions : "echo 'hello there'" ,
1302
+ },
1303
+ {
1304
+ Name : "other" ,
1305
+ Tools : []string {"echo" },
1306
+ Instructions : "echo 'hello somewhere else'" ,
1307
+ },
1308
+ {
1309
+ Name : "echo" ,
1310
+ Tools : []string {"sys.exec" },
1311
+ Description : "Echoes the input" ,
1312
+ Arguments : ObjectSchema ("input" , "The string input to echo" ),
1313
+ Instructions : "#!/bin/bash\n echo ${input}" ,
1314
+ },
1315
+ }
1316
+
1317
+ prg , err := g .LoadTools (context .Background (), tools )
1318
+ if err != nil {
1319
+ t .Fatalf ("Error loading file: %v" , err )
1320
+ }
1321
+
1322
+ if prg .EntryToolID == "" {
1323
+ t .Errorf ("Unexpected entry tool ID: %s" , prg .EntryToolID )
1324
+ }
1325
+
1326
+ if len (prg .ToolSet ) == 0 {
1327
+ t .Errorf ("Unexpected number of tools: %d" , len (prg .ToolSet ))
1328
+ }
1329
+
1330
+ // Name won't be set in this case
1331
+ if prg .Name != "" {
1332
+ t .Errorf ("Unexpected name: %s" , prg .Name )
1333
+ }
1334
+ }
0 commit comments