mirror of
https://github.com/EvolutionAPI/adk-python.git
synced 2025-07-16 04:02:55 -06:00
fix: Use sync request method in VertexAiSessionService. The api_client has it own event loop management.
PiperOrigin-RevId: 761250268
This commit is contained in:
parent
b299241b56
commit
53b14325ce
@ -68,7 +68,7 @@ class VertexAiSessionService(BaseSessionService):
|
|||||||
if state:
|
if state:
|
||||||
session_json_dict['session_state'] = state
|
session_json_dict['session_state'] = state
|
||||||
|
|
||||||
api_response = await self.api_client.async_request(
|
api_response = self.api_client.request(
|
||||||
http_method='POST',
|
http_method='POST',
|
||||||
path=f'reasoningEngines/{reasoning_engine_id}/sessions',
|
path=f'reasoningEngines/{reasoning_engine_id}/sessions',
|
||||||
request_dict=session_json_dict,
|
request_dict=session_json_dict,
|
||||||
@ -80,7 +80,7 @@ class VertexAiSessionService(BaseSessionService):
|
|||||||
|
|
||||||
max_retry_attempt = 5
|
max_retry_attempt = 5
|
||||||
while max_retry_attempt >= 0:
|
while max_retry_attempt >= 0:
|
||||||
lro_response = await self.api_client.async_request(
|
lro_response = self.api_client.request(
|
||||||
http_method='GET',
|
http_method='GET',
|
||||||
path=f'operations/{operation_id}',
|
path=f'operations/{operation_id}',
|
||||||
request_dict={},
|
request_dict={},
|
||||||
@ -93,7 +93,7 @@ class VertexAiSessionService(BaseSessionService):
|
|||||||
max_retry_attempt -= 1
|
max_retry_attempt -= 1
|
||||||
|
|
||||||
# Get session resource
|
# Get session resource
|
||||||
get_session_api_response = await self.api_client.async_request(
|
get_session_api_response = self.api_client.request(
|
||||||
http_method='GET',
|
http_method='GET',
|
||||||
path=f'reasoningEngines/{reasoning_engine_id}/sessions/{session_id}',
|
path=f'reasoningEngines/{reasoning_engine_id}/sessions/{session_id}',
|
||||||
request_dict={},
|
request_dict={},
|
||||||
@ -123,7 +123,7 @@ class VertexAiSessionService(BaseSessionService):
|
|||||||
reasoning_engine_id = _parse_reasoning_engine_id(app_name)
|
reasoning_engine_id = _parse_reasoning_engine_id(app_name)
|
||||||
|
|
||||||
# Get session resource
|
# Get session resource
|
||||||
get_session_api_response = await self.api_client.async_request(
|
get_session_api_response = self.api_client.request(
|
||||||
http_method='GET',
|
http_method='GET',
|
||||||
path=f'reasoningEngines/{reasoning_engine_id}/sessions/{session_id}',
|
path=f'reasoningEngines/{reasoning_engine_id}/sessions/{session_id}',
|
||||||
request_dict={},
|
request_dict={},
|
||||||
@ -141,7 +141,7 @@ class VertexAiSessionService(BaseSessionService):
|
|||||||
last_update_time=update_timestamp,
|
last_update_time=update_timestamp,
|
||||||
)
|
)
|
||||||
|
|
||||||
list_events_api_response = await self.api_client.async_request(
|
list_events_api_response = self.api_client.request(
|
||||||
http_method='GET',
|
http_method='GET',
|
||||||
path=f'reasoningEngines/{reasoning_engine_id}/sessions/{session_id}/events',
|
path=f'reasoningEngines/{reasoning_engine_id}/sessions/{session_id}/events',
|
||||||
request_dict={},
|
request_dict={},
|
||||||
@ -206,7 +206,7 @@ class VertexAiSessionService(BaseSessionService):
|
|||||||
self, *, app_name: str, user_id: str, session_id: str
|
self, *, app_name: str, user_id: str, session_id: str
|
||||||
) -> None:
|
) -> None:
|
||||||
reasoning_engine_id = _parse_reasoning_engine_id(app_name)
|
reasoning_engine_id = _parse_reasoning_engine_id(app_name)
|
||||||
await self.api_client.async_request(
|
self.api_client.request(
|
||||||
http_method='DELETE',
|
http_method='DELETE',
|
||||||
path=f'reasoningEngines/{reasoning_engine_id}/sessions/{session_id}',
|
path=f'reasoningEngines/{reasoning_engine_id}/sessions/{session_id}',
|
||||||
request_dict={},
|
request_dict={},
|
||||||
@ -218,7 +218,7 @@ class VertexAiSessionService(BaseSessionService):
|
|||||||
await super().append_event(session=session, event=event)
|
await super().append_event(session=session, event=event)
|
||||||
|
|
||||||
reasoning_engine_id = _parse_reasoning_engine_id(session.app_name)
|
reasoning_engine_id = _parse_reasoning_engine_id(session.app_name)
|
||||||
await self.api_client.async_request(
|
self.api_client.request(
|
||||||
http_method='POST',
|
http_method='POST',
|
||||||
path=f'reasoningEngines/{reasoning_engine_id}/sessions/{session.id}:appendEvent',
|
path=f'reasoningEngines/{reasoning_engine_id}/sessions/{session.id}:appendEvent',
|
||||||
request_dict=_convert_event_to_json(event),
|
request_dict=_convert_event_to_json(event),
|
||||||
|
@ -125,22 +125,6 @@ class MockApiClient:
|
|||||||
this.event_dict: dict[str, list[Any]] = {}
|
this.event_dict: dict[str, list[Any]] = {}
|
||||||
|
|
||||||
def request(self, http_method: str, path: str, request_dict: dict[str, Any]):
|
def request(self, http_method: str, path: str, request_dict: dict[str, Any]):
|
||||||
"""Mocks the API Client request method."""
|
|
||||||
if http_method == 'GET':
|
|
||||||
if re.match(SESSIONS_REGEX, path):
|
|
||||||
match = re.match(SESSIONS_REGEX, path)
|
|
||||||
return {
|
|
||||||
'sessions': [
|
|
||||||
session
|
|
||||||
for session in self.session_dict.values()
|
|
||||||
if session['userId'] == match.group(2)
|
|
||||||
],
|
|
||||||
}
|
|
||||||
raise ValueError(f'Unsupported sync path: {path}')
|
|
||||||
|
|
||||||
async def async_request(
|
|
||||||
self, http_method: str, path: str, request_dict: dict[str, Any]
|
|
||||||
):
|
|
||||||
"""Mocks the API Client request method."""
|
"""Mocks the API Client request method."""
|
||||||
if http_method == 'GET':
|
if http_method == 'GET':
|
||||||
if re.match(SESSION_REGEX, path):
|
if re.match(SESSION_REGEX, path):
|
||||||
|
Loading…
Reference in New Issue
Block a user