@@ -546,17 +546,21 @@ async def process_event(r: Run, frame: CallFrame | RunFrame | PromptFrame):
546
546
event_output += output .content
547
547
elif frame .type == RunEventType .callFinish :
548
548
call_finish_seen = True
549
+ for output in frame .output :
550
+ event_output += output .content
549
551
550
- run = gptscript .run (os .getcwd () + "/tests/fixtures/global-tools.gpt" ,
552
+ cwd = os .getcwd ().removesuffix ("/tests" )
553
+ run = gptscript .run (cwd + "/tests/fixtures/global-tools.gpt" ,
551
554
Options (
552
555
disableCache = True ,
553
556
credentialOverrides = ["github.com/gptscript-ai/gateway:OPENAI_API_KEY" ],
554
557
),
555
558
event_handlers = [process_event ],
556
559
)
557
560
558
- assert "Hello!" in await run .text (), "Unexpected output from global tool test"
559
- assert "Hello" in event_output , "Unexpected stream output from global tool test"
561
+ output = await run .text ()
562
+ assert "Hello!" in output , "Unexpected output from global tool test: " + output
563
+ assert "Hello" in event_output , "Unexpected stream output from global tool test: " + event_output
560
564
561
565
assert run_start_seen and call_start_seen and call_progress_seen and call_finish_seen and run_finish_seen , \
562
566
f"One of these is False: { run_start_seen } , { call_start_seen } , { call_progress_seen } , { call_finish_seen } , { run_finish_seen } "
@@ -573,7 +577,7 @@ async def process_event(r: Run, frame: CallFrame | RunFrame | PromptFrame):
573
577
confirm_event_found = True
574
578
assert '"ls' in frame .input or '"dir' in frame .input , "Unexpected confirm input: " + frame .input
575
579
await gptscript .confirm (AuthResponse (frame .id , True ))
576
- elif frame .type == RunEventType .callProgress :
580
+ elif frame .type == RunEventType .callProgress or frame . type == RunEventType . callFinish :
577
581
for output in frame .output :
578
582
event_content += output .content
579
583
@@ -610,7 +614,7 @@ async def process_event(r: Run, frame: CallFrame | RunFrame | PromptFrame):
610
614
confirm_event_found = True
611
615
assert '"ls"' in frame .input , "Unexpected confirm input: " + frame .input
612
616
await gptscript .confirm (AuthResponse (frame .id , False , "I will not allow it!" ))
613
- elif frame .type == RunEventType .callProgress :
617
+ elif frame .type == RunEventType .callProgress or frame . type == RunEventType . callFinish :
614
618
for output in frame .output :
615
619
event_content += output .content
616
620
@@ -637,9 +641,9 @@ async def process_event(r: Run, frame: CallFrame | RunFrame | PromptFrame):
637
641
if frame .type == RunEventType .prompt :
638
642
prompt_event_found = True
639
643
assert len (frame .fields ) == 1 , "Unexpected number of fields: " + str (frame .fields )
640
- assert "first name" in frame .fields [0 ], "Unexpected field: " + frame .fields [0 ]
641
- await gptscript .prompt (PromptResponse (frame .id , {frame .fields [0 ]: "Clicky" }))
642
- elif frame .type == RunEventType .callProgress :
644
+ assert "first name" in frame .fields [0 ]. name , "Unexpected field: " + frame .fields [0 ]. name
645
+ await gptscript .prompt (PromptResponse (frame .id , {frame .fields [0 ]. name : "Clicky" }))
646
+ elif frame .type == RunEventType .callProgress or frame . type == RunEventType . callFinish :
643
647
for output in frame .output :
644
648
event_content += output .content
645
649
@@ -667,10 +671,10 @@ async def process_event(r: Run, frame: CallFrame | RunFrame | PromptFrame):
667
671
if frame .type == RunEventType .prompt :
668
672
prompt_event_found = True
669
673
assert len (frame .fields ) == 1 , "Unexpected number of fields: " + str (frame .fields )
670
- assert "first name" in frame .fields [0 ], "Unexpected field: " + frame .fields [0 ]
674
+ assert "first name" in frame .fields [0 ]. name , "Unexpected field: " + frame .fields [0 ]. name
671
675
assert "first_name" in frame .metadata , "Unexpected metadata: " + str (frame .metadata )
672
676
assert frame .metadata ["first_name" ] == "Clicky" , "Unexpected metadata: " + str (frame .metadata )
673
- await gptscript .prompt (PromptResponse (frame .id , {frame .fields [0 ]: "Clicky" }))
677
+ await gptscript .prompt (PromptResponse (frame .id , {frame .fields [0 ]. name : "Clicky" }))
674
678
675
679
out = await gptscript .run (
676
680
"sys.prompt" ,
@@ -691,8 +695,8 @@ async def process_event(r: Run, frame: CallFrame | RunFrame | PromptFrame):
691
695
if frame .type == RunEventType .prompt :
692
696
prompt_event_found = True
693
697
assert len (frame .fields ) == 1 , "Unexpected number of fields: " + str (frame .fields )
694
- assert "first name" in frame .fields [0 ], "Unexpected field: " + frame .fields [0 ]
695
- await gptscript .prompt (PromptResponse (frame .id , {frame .fields [0 ]: "Clicky" }))
698
+ assert "first name" in frame .fields [0 ]. name , "Unexpected field: " + frame .fields [0 ]. name
699
+ await gptscript .prompt (PromptResponse (frame .id , {frame .fields [0 ]. name : "Clicky" }))
696
700
697
701
tool = ToolDef (
698
702
tools = ["sys.prompt" ],
@@ -727,7 +731,7 @@ async def test_run_file_with_metadata(gptscript):
727
731
728
732
@pytest .mark .asyncio
729
733
async def test_parse_with_metadata_then_run (gptscript ):
730
- cwd = os .getcwd ().removesuffix ("tests" )
734
+ cwd = os .getcwd ().removesuffix ("/ tests" )
731
735
tools = await gptscript .parse (cwd + "/tests/fixtures/parse-with-metadata.gpt" )
732
736
run = gptscript .evaluate (tools [0 ])
733
737
assert "200" == await run .text (), "Expect file to have correct output"
0 commit comments