Skip to content

Commit 04820cb

Browse files
Jacksunweicopybara-github
authored andcommitted
chore: Fixes a few samples for the breaking session service change.
PiperOrigin-RevId: 759354632
1 parent 509db3f commit 04820cb

2 files changed

Lines changed: 2 additions & 50 deletions

File tree

contributing/samples/hello_world/asyncio_run.py renamed to contributing/samples/hello_world/main.py

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
import asyncio
1616
import time
17-
import warnings
1817

1918
import agent
2019
from dotenv import load_dotenv
@@ -27,7 +26,6 @@
2726
from google.genai import types
2827

2928
load_dotenv(override=True)
30-
warnings.filterwarnings('ignore', category=UserWarning)
3129
logs.log_to_tmp_folder()
3230

3331

@@ -42,7 +40,7 @@ async def main():
4240
artifact_service=artifact_service,
4341
session_service=session_service,
4442
)
45-
session_11 = session_service.create_session(
43+
session_11 = await session_service.create_session(
4644
app_name=app_name, user_id=user_id_1
4745
)
4846

@@ -97,49 +95,5 @@ async def run_prompt_bytes(session: Session, new_message: str):
9795
print('Total time:', end_time - start_time)
9896

9997

100-
def main_sync():
101-
app_name = 'my_app'
102-
user_id_1 = 'user1'
103-
session_service = InMemorySessionService()
104-
artifact_service = InMemoryArtifactService()
105-
runner = Runner(
106-
app_name=app_name,
107-
agent=agent.root_agent,
108-
artifact_service=artifact_service,
109-
session_service=session_service,
110-
)
111-
session_11 = session_service.create_session(
112-
app_name=app_name, user_id=user_id_1
113-
)
114-
115-
def run_prompt(session: Session, new_message: str):
116-
content = types.Content(
117-
role='user', parts=[types.Part.from_text(text=new_message)]
118-
)
119-
print('** User says:', content.model_dump(exclude_none=True))
120-
for event in runner.run(
121-
user_id=user_id_1,
122-
session_id=session.id,
123-
new_message=content,
124-
):
125-
if event.content.parts and event.content.parts[0].text:
126-
print(f'** {event.author}: {event.content.parts[0].text}')
127-
128-
start_time = time.time()
129-
print('Start time:', start_time)
130-
print('------------------------------------')
131-
run_prompt(session_11, 'Hi')
132-
run_prompt(session_11, 'Roll a die with 100 sides.')
133-
run_prompt(session_11, 'Roll a die again with 100 sides.')
134-
run_prompt(session_11, 'What numbers did I got?')
135-
end_time = time.time()
136-
print('------------------------------------')
137-
print('End time:', end_time)
138-
print('Total time:', end_time - start_time)
139-
140-
14198
if __name__ == '__main__':
142-
print('--------------ASYNC--------------------')
14399
asyncio.run(main())
144-
print('--------------SYNC--------------------')
145-
main_sync()

contributing/samples/hello_world_litellm/asyncio_run.py renamed to contributing/samples/hello_world_litellm/main.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
import asyncio
1717
import time
18-
import warnings
1918

2019
import agent
2120
from dotenv import load_dotenv
@@ -27,7 +26,6 @@
2726
from google.genai import types
2827

2928
load_dotenv(override=True)
30-
warnings.filterwarnings('ignore', category=UserWarning)
3129
logs.log_to_tmp_folder()
3230

3331

@@ -42,7 +40,7 @@ async def main():
4240
artifact_service=artifact_service,
4341
session_service=session_service,
4442
)
45-
session_11 = session_service.create_session(
43+
session_11 = await session_service.create_session(
4644
app_name=app_name, user_id=user_id_1
4745
)
4846

0 commit comments

Comments
 (0)