mirror of
https://github.com/encounter/adk-python.git
synced 2026-07-09 18:19:28 -07:00
fix: Fixes a bug introduced by the underlying google genai library
We need to set project and location parameters when we instantiate the Google GenAI library Client for VertexAi. This used to work before through environment variables but it doesn't seem to work anymore. So we are updating the `ApigeeLlm` wrapper to read from `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` environment variables and pass to the Client constructor. PiperOrigin-RevId: 829569362
This commit is contained in:
committed by
Copybara-Service
parent
9e22cc4022
commit
34ea2edfd2
@@ -37,6 +37,8 @@ logger = logging.getLogger('google_adk.' + __name__)
|
||||
|
||||
_APIGEE_PROXY_URL_ENV_VARIABLE_NAME = 'APIGEE_PROXY_URL'
|
||||
_GOOGLE_GENAI_USE_VERTEXAI_ENV_VARIABLE_NAME = 'GOOGLE_GENAI_USE_VERTEXAI'
|
||||
_PROJECT_ENV_VARIABLE_NAME = 'GOOGLE_CLOUD_PROJECT'
|
||||
_LOCATION_ENV_VARIABLE_NAME = 'GOOGLE_CLOUD_LOCATION'
|
||||
|
||||
|
||||
class ApigeeLlm(Gemini):
|
||||
@@ -90,6 +92,24 @@ class ApigeeLlm(Gemini):
|
||||
raise ValueError(f'Invalid model string: {model}')
|
||||
|
||||
self._isvertexai = _identify_vertexai(model)
|
||||
|
||||
# Set the project and location for Vertex AI.
|
||||
if self._isvertexai:
|
||||
self._project = os.environ.get(_PROJECT_ENV_VARIABLE_NAME)
|
||||
self._location = os.environ.get(_LOCATION_ENV_VARIABLE_NAME)
|
||||
|
||||
if not self._project:
|
||||
raise ValueError(
|
||||
f'The {_PROJECT_ENV_VARIABLE_NAME} environment variable must be'
|
||||
' set.'
|
||||
)
|
||||
|
||||
if not self._location:
|
||||
raise ValueError(
|
||||
f'The {_LOCATION_ENV_VARIABLE_NAME} environment variable must be'
|
||||
' set.'
|
||||
)
|
||||
|
||||
self._api_version = _identify_api_version(model)
|
||||
self._proxy_url = proxy_url or os.environ.get(
|
||||
_APIGEE_PROXY_URL_ENV_VARIABLE_NAME
|
||||
@@ -128,9 +148,15 @@ class ApigeeLlm(Gemini):
|
||||
**kwargs_for_http_options,
|
||||
)
|
||||
|
||||
kwargs_for_client = {}
|
||||
kwargs_for_client['vertexai'] = self._isvertexai
|
||||
if self._isvertexai:
|
||||
kwargs_for_client['project'] = self._project
|
||||
kwargs_for_client['location'] = self._location
|
||||
|
||||
return Client(
|
||||
vertexai=self._isvertexai,
|
||||
http_options=http_options,
|
||||
**kwargs_for_client,
|
||||
)
|
||||
|
||||
@override
|
||||
|
||||
Reference in New Issue
Block a user