Skip to content

Commit 34f7d40

Browse files
committed
chore: add test for prompt with metadata
Signed-off-by: Donnie Adams <[email protected]>
1 parent 6499b85 commit 34f7d40

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tests/test_gptscript.py

+22
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,28 @@ async def process_event(r: Run, frame: CallFrame | RunFrame | PromptFrame):
585585
assert "Clicky" in event_content, "Unexpected event output: " + event_content
586586

587587

588+
@pytest.mark.asyncio
589+
async def test_prompt_with_metadata(gptscript):
590+
prompt_event_found = False
591+
592+
async def process_event(r: Run, frame: CallFrame | RunFrame | PromptFrame):
593+
nonlocal prompt_event_found
594+
if frame.type == RunEventType.prompt:
595+
prompt_event_found = True
596+
assert len(frame.fields) == 1, "Unexpected number of fields: " + str(frame.fields)
597+
assert "first name" in frame.fields[0], "Unexpected field: " + frame.fields[0]
598+
await gptscript.prompt(PromptResponse(frame.id, {frame.fields[0]: "Clicky"}))
599+
600+
out = await gptscript.run(
601+
"sys.prompt",
602+
Options(prompt=True, disableCache=True, input='{"fields": "first name", "metadata": {"first_name": "Clicky"}}'),
603+
event_handlers=[process_event],
604+
).text()
605+
606+
assert prompt_event_found, "No prompt event"
607+
assert "Clicky" in out, "Unexpected output: " + out
608+
609+
588610
@pytest.mark.asyncio
589611
async def test_prompt_without_prompt_allowed(gptscript):
590612
prompt_event_found = False

0 commit comments

Comments
 (0)