@@ -161,9 +161,7 @@ func TestAbortRun(t *testing.T) {
161
161
func TestSimpleEvaluate (t * testing.T ) {
162
162
tool := ToolDef {Instructions : "What is the capital of the united states?" }
163
163
164
- run , err := g .Evaluate (context .Background (), Options {
165
- GlobalOptions : GlobalOptions {},
166
- }, tool )
164
+ run , err := g .Evaluate (context .Background (), Options {DisableCache : true }, tool )
167
165
if err != nil {
168
166
t .Errorf ("Error executing tool: %v" , err )
169
167
}
@@ -190,6 +188,17 @@ func TestSimpleEvaluate(t *testing.T) {
190
188
if run .Program () == nil {
191
189
t .Error ("Run program not set" )
192
190
}
191
+
192
+ var promptTokens , completionTokens , totalTokens int
193
+ for _ , c := range run .calls {
194
+ promptTokens += c .Usage .PromptTokens
195
+ completionTokens += c .Usage .CompletionTokens
196
+ totalTokens += c .Usage .TotalTokens
197
+ }
198
+
199
+ if promptTokens == 0 || completionTokens == 0 || totalTokens == 0 {
200
+ t .Errorf ("Usage not set: %d, %d, %d" , promptTokens , completionTokens , totalTokens )
201
+ }
193
202
}
194
203
195
204
func TestEvaluateWithContext (t * testing.T ) {
@@ -285,6 +294,16 @@ func TestEvaluateWithToolList(t *testing.T) {
285
294
if ! strings .Contains (out , "hello there" ) {
286
295
t .Errorf ("Unexpected output: %s" , out )
287
296
}
297
+
298
+ // In this case, we expect the total number of tool results to be 1
299
+ var toolResults int
300
+ for _ , c := range run .calls {
301
+ toolResults += c .ToolResults
302
+ }
303
+
304
+ if toolResults != 1 {
305
+ t .Errorf ("Unexpected number of tool results: %d" , toolResults )
306
+ }
288
307
}
289
308
290
309
func TestEvaluateWithToolListAndSubTool (t * testing.T ) {
@@ -361,6 +380,54 @@ func TestStreamEvaluate(t *testing.T) {
361
380
}
362
381
}
363
382
383
+ func TestSimpleRun (t * testing.T ) {
384
+ wd , err := os .Getwd ()
385
+ if err != nil {
386
+ t .Fatalf ("Error getting working directory: %v" , err )
387
+ }
388
+
389
+ run , err := g .Run (context .Background (), wd + "/test/catcher.gpt" , Options {})
390
+ if err != nil {
391
+ t .Fatalf ("Error executing file: %v" , err )
392
+ }
393
+
394
+ out , err := run .Text ()
395
+ if err != nil {
396
+ t .Errorf ("Error reading output: %v" , err )
397
+ }
398
+
399
+ if ! strings .Contains (out , "Salinger" ) {
400
+ t .Errorf ("Unexpected output: %s" , out )
401
+ }
402
+
403
+ if len (run .ErrorOutput ()) != 0 {
404
+ t .Error ("Should have no stderr output" )
405
+ }
406
+
407
+ // Run it a second time, ensuring the same output and that a cached response is used
408
+ run , err = g .Run (context .Background (), wd + "/test/catcher.gpt" , Options {})
409
+ if err != nil {
410
+ t .Fatalf ("Error executing file: %v" , err )
411
+ }
412
+
413
+ secondOut , err := run .Text ()
414
+ if err != nil {
415
+ t .Errorf ("Error reading output: %v" , err )
416
+ }
417
+
418
+ if secondOut != out {
419
+ t .Errorf ("Unexpected output on second run: %s != %s" , out , secondOut )
420
+ }
421
+
422
+ // In this case, we expect a single call and that the response is cached
423
+ for _ , c := range run .calls {
424
+ if ! c .ChatResponseCached {
425
+ t .Error ("Chat response should be cached" )
426
+ }
427
+ break
428
+ }
429
+ }
430
+
364
431
func TestStreamRun (t * testing.T ) {
365
432
wd , err := os .Getwd ()
366
433
if err != nil {
0 commit comments