From 04820cb0a75da9029245b7fc9bb2000c13258954 Mon Sep 17 00:00:00 2001 From: "Wei Sun (Jack)" Date: Thu, 15 May 2025 16:43:47 -0700 Subject: [PATCH] chore: Fixes a few samples for the breaking session service change. PiperOrigin-RevId: 759354632 --- .../hello_world/{asyncio_run.py => main.py} | 48 +------------------ .../{asyncio_run.py => main.py} | 4 +- 2 files changed, 2 insertions(+), 50 deletions(-) rename contributing/samples/hello_world/{asyncio_run.py => main.py} (67%) rename contributing/samples/hello_world_litellm/{asyncio_run.py => main.py} (95%) diff --git a/contributing/samples/hello_world/asyncio_run.py b/contributing/samples/hello_world/main.py similarity index 67% rename from contributing/samples/hello_world/asyncio_run.py rename to contributing/samples/hello_world/main.py index 53768f5..a87a8a3 100755 --- a/contributing/samples/hello_world/asyncio_run.py +++ b/contributing/samples/hello_world/main.py @@ -14,7 +14,6 @@ import asyncio import time -import warnings import agent from dotenv import load_dotenv @@ -27,7 +26,6 @@ from google.adk.sessions import Session from google.genai import types load_dotenv(override=True) -warnings.filterwarnings('ignore', category=UserWarning) logs.log_to_tmp_folder() @@ -42,7 +40,7 @@ async def main(): artifact_service=artifact_service, session_service=session_service, ) - session_11 = session_service.create_session( + session_11 = await session_service.create_session( app_name=app_name, user_id=user_id_1 ) @@ -97,49 +95,5 @@ async def main(): print('Total time:', end_time - start_time) -def main_sync(): - app_name = 'my_app' - user_id_1 = 'user1' - session_service = InMemorySessionService() - artifact_service = InMemoryArtifactService() - runner = Runner( - app_name=app_name, - agent=agent.root_agent, - artifact_service=artifact_service, - session_service=session_service, - ) - session_11 = session_service.create_session( - app_name=app_name, user_id=user_id_1 - ) - - def run_prompt(session: Session, new_message: str): - content = types.Content( - role='user', parts=[types.Part.from_text(text=new_message)] - ) - print('** User says:', content.model_dump(exclude_none=True)) - for event in runner.run( - user_id=user_id_1, - session_id=session.id, - new_message=content, - ): - if event.content.parts and event.content.parts[0].text: - print(f'** {event.author}: {event.content.parts[0].text}') - - start_time = time.time() - print('Start time:', start_time) - print('------------------------------------') - run_prompt(session_11, 'Hi') - run_prompt(session_11, 'Roll a die with 100 sides.') - run_prompt(session_11, 'Roll a die again with 100 sides.') - run_prompt(session_11, 'What numbers did I got?') - end_time = time.time() - print('------------------------------------') - print('End time:', end_time) - print('Total time:', end_time - start_time) - - if __name__ == '__main__': - print('--------------ASYNC--------------------') asyncio.run(main()) - print('--------------SYNC--------------------') - main_sync() diff --git a/contributing/samples/hello_world_litellm/asyncio_run.py b/contributing/samples/hello_world_litellm/main.py similarity index 95% rename from contributing/samples/hello_world_litellm/asyncio_run.py rename to contributing/samples/hello_world_litellm/main.py index f2fd4ae..e95353b 100644 --- a/contributing/samples/hello_world_litellm/asyncio_run.py +++ b/contributing/samples/hello_world_litellm/main.py @@ -15,7 +15,6 @@ import asyncio import time -import warnings import agent from dotenv import load_dotenv @@ -27,7 +26,6 @@ from google.adk.sessions import Session from google.genai import types load_dotenv(override=True) -warnings.filterwarnings('ignore', category=UserWarning) logs.log_to_tmp_folder() @@ -42,7 +40,7 @@ async def main(): artifact_service=artifact_service, session_service=session_service, ) - session_11 = session_service.create_session( + session_11 = await session_service.create_session( app_name=app_name, user_id=user_id_1 )