8000 fix: Use sync request method in VertexAiSessionService. The api_clien… · Jay-flow/adk-python@53b1432 · GitHub
[go: up one dir, main page]

Skip to content

Commit 53b1432

Browse files
DeanChensjcopybara-github
authored andcommitted
fix: Use sync request method in VertexAiSessionService. The api_client has it own event loop management.
PiperOrigin-RevId: 761250268
1 parent b299241 commit 53b1432

File tree

2 files changed

+7
-23
lines changed

2 files changed

+7
-23
lines changed

src/google/adk/sessions/vertex_ai_session_service.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ async def create_session(
6868
if state:
6969
session_json_dict['session_state'] = state
7070

71-
api_response = await self.api_client.async_request(
71+
api_response = self.api_client.request(
7272
http_method='POST',
7373
path=f'reasoningEngines/{reasoning_engine_id}/sessions',
7474
request_dict=session_json_dict,
@@ -80,7 +80,7 @@ async def create_session(
8080

8181
max_retry_attempt = 5
8282
while max_retry_attempt >= 0:
83-
lro_response = await self.api_client.async_request(
83+
lro_response = self.api_client.request(
8484
http_method='GET',
8585
path=f'operations/{operation_id}',
8686
request_dict={},
@@ -93,7 +93,7 @@ async def create_session(
9393
max_retry_attempt -= 1
9494

9595
# Get session resource
96-
get_session_api_response = await self.api_client.async_request(
96+
get_session_api_response = self.api_client.request(
9797
http_method='GET',
9898
path=f'reasoningEngines/{reasoning_engine_id}/sessions/{session_id}',
9999
request_dict={},
@@ -123,7 +123,7 @@ async def get_session(
123123
reasoning_engine_id = _parse_reasoning_engine_id(app_name)
124124

125125
# Get session resource
126-
get_session_api_response = await self.api_client.async_request(
126+
get_session_api_response = self.api_client.request(
127127
http_method='GET',
128128
path=f'reasoningEngines/{reasoning_engine_id}/sessions/{session_id}',
129129
request_dict={},
@@ -141,7 +141,7 @@ async def get_session(
141141
last_update_time=update_timestamp,
142142
)
143143

144-
list_events_api_response = await self.api_client.async_request(
144+
list_events_api_response = self.api_client.request(
145145
http_method='GET',
146146
path=f'reasoningEngines/{reasoning_engine_id}/sessions/{session_id}/events',
147147
request_dict={},
@@ -206,7 +206,7 @@ async def delete_session(
206206
self, *, app_name: str, user_id: str, session_id: str
207207
) -> None:
208208
reasoning_engine_id = _parse_reasoning_engine_id(app_name)
209-
await self.api_client.async_request(
209+
self.api_client.request(
210210
http_method='DELETE',
211211
path=f'reasoningEngines/{reasoning_engine_id}/sessions/{session_id}',
212212
request_dict={},
@@ -218,7 +218,7 @@ async def append_event(self, session: Session, event: Event) -> Event:
218218
await super().append_event(session=session, event=event)
219219

220220
reasoning_engine_id = _parse_reasoning_engine_id(session.app_name)
221-
await self.api_client.async_request(
221+
self.api_client.request(
222222
http_method='POST',
223223
path=f'reasoningEngines/{reasoning_engine_id}/sessions/{session.id}:appendEvent',
224224
request_dict=_convert_event_to_json(event),

tests/unittests/sessions/test_vertex_ai_session_service.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -125,22 +125,6 @@ def __init__(self) -> None:
125125
this.event_dict: dict[str, list[Any]] = {}
126126

127127
def request(self, http_method: str, path: str, request_dict: dict[str, Any]):
128-
"""Mocks the API Client request method."""
129-
if http_method == 'GET':
130-
if re.match(SESSIONS_REGEX, path):
131-
match = re.match(SESSIONS_REGEX, path)
132-
return {
133-
'sessions': [
134-
session
135-
for session in self.session_dict.values()
136-
if session['userId'] == match.group(2)
137-
],
138-
}
139-
raise ValueError(f'Unsupported sync path: {path}')
140-
141-
async def async_request(
142-
self, http_method: str, path: str, request_dict: dict[str, Any]
143-
):
144128
"""Mocks the API Client request method."""
145129
if http_method == 'GET':
146130
if re.match(SESSION_REGEX, path):

0 commit comments

Comments
 (0)
0