Skip to content

Commit bcd925f

Browse files
wuliang229GWeale
authored andcommitted
chore: Improve event content handling and minor prompt adjustments
Co-authored-by: Liang Wu <wuliang@google.com> PiperOrigin-RevId: 895518689 Change-Id: Ia1b7b3f052d8c04f2daaaa8b52924427005dd557
1 parent ddce1e3 commit bcd925f

File tree

1 file changed

+12
-4
lines changed
  • contributing/samples/hello_world

1 file changed

+12
-4
lines changed

contributing/samples/hello_world/main.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,15 @@ async def run_prompt(session: Session, new_message: str):
4848
session_id=session.id,
4949
new_message=content,
5050
):
51-
if event.content.parts and event.content.parts[0].text:
52-
print(f'** {event.author}: {event.content.parts[0].text}')
51+
if event.content.parts:
52+
for part in event.content.parts:
53+
if part.text:
54+
print(f'** {event.author}: {part.text}')
55+
if part.function_call:
56+
print(
57+
f'** {event.author} calls tool: {part.function_call.name} with'
58+
f' args {part.function_call.args}'
59+
)
5360

5461
async def run_prompt_bytes(session: Session, new_message: str):
5562
content = types.Content(
@@ -74,6 +81,7 @@ async def check_rolls_in_state(rolls_size: int):
7481
session = await runner.session_service.get_session(
7582
app_name=app_name, user_id=user_id_1, session_id=session_11.id
7683
)
84+
print('** session.state:', session.state)
7785
assert len(session.state['rolls']) == rolls_size
7886
for roll in session.state['rolls']:
7987
assert roll > 0 and roll <= 100
@@ -82,9 +90,9 @@ async def check_rolls_in_state(rolls_size: int):
8290
print('Start time:', start_time)
8391
print('------------------------------------')
8492
await run_prompt(session_11, 'Hi')
85-
await run_prompt(session_11, 'Roll a die with 100 sides')
93+
await run_prompt(session_11, 'Roll a dice with 100 sides')
8694
await check_rolls_in_state(1)
87-
await run_prompt(session_11, 'Roll a die again with 100 sides.')
95+
await run_prompt(session_11, 'Roll a dice again with 100 sides.')
8896
await check_rolls_in_state(2)
8997
await run_prompt(session_11, 'What numbers did I got?')
9098
await run_prompt_bytes(session_11, 'Hi bytes')

0 commit comments

Comments
 (0)