8000 Update samples for async session changes and remove exp suffix from g… · ditinagrawal/adk-python@01cf186 · GitHub
[go: up one dir, main page]

Skip to content

Commit 01cf186

Browse files
selcukguncopybara-github
authored andcommitted
Update samples for async session changes and remove exp suffix from gemini model
PiperOrigin-RevId: 759364113
1 parent 04820cb commit 01cf186

File tree

7 files changed

+8
-112
lines changed

7 files changed

+8
-112
lines changed

contributing/samples/artifact_save_text/agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ async def log_query(tool_context: ToolContext, query: str):
2424

2525

2626
root_agent = Agent(
27-
model='gemini-2.0-flash-exp',
27+
model='gemini-2.0-flash',
2828
name='log_agent',
2929
description='Log user query.',
3030
instruction="""Always log the user query and reploy "kk, I've logged."

contributing/samples/callbacks/agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def after_tool_cb3(tool, args, tool_context, tool_response):
145145

146146

147147
root_agent = Agent(
148-
model='gemini-2.0-flash-exp',
148+
model='gemini-2.0-flash',
149149
name='data_processing_agent',
150150
description=(
151151
'hello world agent that can roll a dice of 8 sides and check prime'

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

Lines changed: 1 addition & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import agent
2020
from dotenv import load_dotenv
2121
from google.adk import Runner
22-
from google.adk.agents.run_config import RunConfig
2322
from google.adk.artifacts import InMemoryArtifactService
2423
from google.adk.cli.utils import logs
2524
from google.adk.sessions import InMemorySessionService
@@ -42,7 +41,7 @@ async def main():
4241
artifact_service=artifact_service,
4342
session_service=session_service,
4443
)
45-
session_11 = session_service.create_session(
44+
session_11 = await session_service.create_session(
4645
app_name=app_name, user_id=user_id_1
4746
)
4847

@@ -59,33 +58,13 @@ async def run_prompt(session: Session, new_message: str):
5958
if event.content.parts and event.content.parts[0].text:
6059
print(f'** {event.author}: {event.content.parts[0].text}')
6160

62-
async def run_prompt_bytes(session: Session, new_message: str):
63-
content = types.Content(
64-
role='user',
65-
parts=[
66-
types.Part.from_bytes(
67-
data=str.encode(new_message), mime_type='text/plain'
68-
)
69-
],
70-
)
71-
print('** User says:', content.model_dump(exclude_none=True))
72-
async for event in runner.run_async(
73-
user_id=user_id_1,
74-
session_id=session.id,
75-
new_message=content,
76-
run_config=RunConfig(save_input_blobs_as_artifacts=True),
77-
):
78-
if event.content.parts and event.content.parts[0].text:
79-
print(f'** {event.author}: {event.content.parts[0].text}')
80-
8161
start_time = time.time()
8262
print('Start time:', start_time)
8363
print('------------------------------------')
8464
await run_prompt(session_11, 'Hi')
8565
await run_prompt(session_11, 'Roll a die with 100 sides')
8666
await run_prompt(session_11, 'Roll a die again with 100 sides.')
8767
await run_prompt(session_11, 'What numbers did I got?')
88-
await run_prompt_bytes(session_11, 'Hi bytes')
8968
print(
9069
await artifact_service.list_artifact_keys(
9170
app_name=app_name, user_id=user_id_1, session_id=session_11.id
@@ -97,49 +76,5 @@ async def run_prompt_bytes(session: Session, new_message: str):
9776
print('Total time:', end_time - start_time)
9877

9978

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-
14179
if __name__ == '__main__':
142-
print('--------------ASYNC--------------------')
14380
asyncio.run(main())
144-
print('--------------SYNC--------------------')
145-
main_sync()

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

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ async def main():
4141
artifact_service=artifact_service,
4242
session_service=session_service,
4343
)
44-
session_11 = session_service.create_session(app_name, user_id_1)
44+
session_11 = await session_service.create_session(app_name, user_id_1)
4545

4646
async def run_prompt(session: Session, new_message: str):
4747
content = types.Content(
@@ -69,44 +69,5 @@ async def run_prompt(session: Session, new_message: str):
6969
print('Total time:', end_time - start_time)
7070

7171

72-
def main_sync():
73-
app_name = 'my_app'
74-
user_id_1 = 'user1'
75-
session_service = InMemorySessionService()
76-
artifact_service = InMemoryArtifactService()
77-
runner = Runner(
78-
app_name=app_name,
79-
agent=agent.root_agent,
80-
artifact_service=artifact_service,
81-
session_service=session_service,
82-
)
83-
session_11 = session_service.create_session(app_name, user_id_1)
84-
85-
def run_prompt(session: Session, new_message: str):
86-
content = types.Content(
87-
role='user', parts=[types.Part.from_text(text=new_message)]
88-
)
89-
print('** User says:', content.model_dump(exclude_none=True))
90-
for event in runner.run_sync(
91-
session=session,
92-
new_message=content,
93-
):
94-
if event.content.parts and event.content.parts[0].text:
95-
print(f'** {event.author}: {event.content.parts[0].text}')
96-
97-
start_time = time.time()
98-
print('Start time:', start_time)
99-
print('------------------------------------')
100-
run_prompt(session_11, 'Hi')
101-
run_prompt(session_11, 'Roll a die.')
102-
run_prompt(session_11, 'Roll a die again.')
103-
run_prompt(session_11, 'What numbers did I got?')
104-
end_time = time.time()
105-
print('------------------------------------')
106-
print('End time:', end_time)
107-
print('Total time:', end_time - start_time)
108-
109-
11072
if __name__ == '__main__':
11173
asyncio.run(main())
112-
main_sync()

contributing/samples/hello_world/agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ async def check_prime(nums: list[int]) -> str:
6666
)
6767

6868
root_agent = Agent(
69-
model='gemini-2.0-flash-exp',
69+
model='gemini-2.0-flash',
7070
name='data_processing_agent',
7171
description=(
7272
'hello world agent that can roll a dice of 8 sides and check prime'

contributing/samples/simple_sequential_agent/agent.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def roll_die(sides: int) -> int:
2828
roll_agent = LlmAgent(
2929
name="roll_agent",
3030
description="Handles rolling dice of different sizes.",
31-
model="gemini-2.0-flash-exp",
31+
model="gemini-2.0-flash",
3232
instruction="""
3333
You are responsible for rolling dice based on the user's request.
3434
When asked to roll a die, you must call the roll_die tool with the number of sides as an integer.
@@ -69,7 +69,7 @@ def check_prime(nums: list[int]) -> str:
6969
prime_agent = LlmAgent(
7070
name="prime_agent",
7171
description="Handles checking if numbers are prime.",
72-
model="gemini-2.0-flash-exp",
72+
model="gemini-2.0-flash",
7373
instruction="""
7474
You are responsible for checking whether numbers are prime.
7575
When asked to check primes, you must call the check_prime tool with a list of integers.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ async def main():
4242
artifact_service=artifact_service,
4343
session_service=session_service,
4444
)
45-
session_11 = session_service.create_session(
45+
session_11 = await session_service.create_session(
4646
app_name=app_name, user_id=user_id_1
4747
)
4848

0 commit comments

Comments
 (0)
0