()
| 31 | |
| 32 | |
| 33 | async def main(): |
| 34 | app_name = 'my_gemma_app' |
| 35 | user_id_1 = 'user1' |
| 36 | session_service = InMemorySessionService() |
| 37 | artifact_service = InMemoryArtifactService() |
| 38 | runner = Runner( |
| 39 | app_name=app_name, |
| 40 | agent=agent.root_agent, |
| 41 | artifact_service=artifact_service, |
| 42 | session_service=session_service, |
| 43 | ) |
| 44 | session_11 = await session_service.create_session( |
| 45 | app_name=app_name, user_id=user_id_1 |
| 46 | ) |
| 47 | |
| 48 | async def run_prompt(session: Session, new_message: str): |
| 49 | content = types.Content( |
| 50 | role='user', parts=[types.Part.from_text(text=new_message)] |
| 51 | ) |
| 52 | print('** User says:', content.model_dump(exclude_none=True)) |
| 53 | async for event in runner.run_async( |
| 54 | user_id=user_id_1, |
| 55 | session_id=session.id, |
| 56 | new_message=content, |
| 57 | ): |
| 58 | if event.content.parts and event.content.parts[0].text: |
| 59 | print(f'** {event.author}: {event.content.parts[0].text}') |
| 60 | |
| 61 | start_time = time.time() |
| 62 | print('Start time:', start_time) |
| 63 | print('------------------------------------') |
| 64 | await run_prompt(session_11, 'Hi, introduce yourself.') |
| 65 | await run_prompt( |
| 66 | session_11, 'Roll a die with 100 sides and check if it is prime' |
| 67 | ) |
| 68 | await run_prompt(session_11, 'Roll it again.') |
| 69 | await run_prompt(session_11, 'What numbers did I get?') |
| 70 | end_time = time.time() |
| 71 | print('------------------------------------') |
| 72 | print('End time:', end_time) |
| 73 | print('Total time:', end_time - start_time) |
| 74 | |
| 75 | |
| 76 | if __name__ == '__main__': |
no test coverage detected