Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions packages/genkit-google-genai/src/genkit_google_genai/_google.py
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,7 @@ def __init__(
location
or os.getenv(const.GOOGLE_CLOUD_LOCATION)
or os.getenv(const.GCLOUD_LOCATION)
or const.DEFAULT_REGION
or (None if (api_key and not self._project) else const.DEFAULT_REGION)
)

opts = _plugin_http_options(
Expand All @@ -1157,11 +1157,11 @@ def __init__(
self._http_client_factory = _loop_local_http_client(http_client_factory)
self._base_url_pinned = bool(opts.base_url)
self._legacy_response_schema = legacy_response_schema
multi_region = const.is_multi_regional_location(self._location)
if multi_region and not self._base_url_pinned:
if const.is_multi_regional_location(self._location) and not self._base_url_pinned:
# Multi-regions ('us', 'eu') are served from dedicated endpoints
# that the google-genai SDK does not derive itself.
opts.base_url = const.multi_regional_base_url(self._location)
multi_region = const.is_multi_regional_location(self._location)

# Resolve the project here rather than leaving it to the SDK: with any
# base_url set the SDK skips its own ADC lookup, evaluator registration
Expand Down Expand Up @@ -1236,7 +1236,7 @@ async def init(self) -> list[Action | BackgroundAction[Any, Any]]:
create_vertex_evaluators(
list(VertexAIEvaluationMetricType),
project=self._project,
location=self._location,
location=self._location or const.DEFAULT_REGION,
)
)

Expand Down Expand Up @@ -1322,7 +1322,7 @@ def _resolve_evaluator(self, name: str) -> Action | None:
[action] = create_vertex_evaluators(
[metric_type],
project=self._project,
location=self._location,
location=self._location or const.DEFAULT_REGION,
)
return action

Expand Down Expand Up @@ -1449,7 +1449,7 @@ async def list_actions(self) -> list[Action | BackgroundAction[Any, Any]]:
create_vertex_evaluators(
list(VertexAIEvaluationMetricType),
project=self._project,
location=self._location,
location=self._location or const.DEFAULT_REGION,
)
)

Expand Down
8 changes: 8 additions & 0 deletions packages/genkit-google-genai/tests/vertexai_location_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,14 @@ def test_api_key_skips_adc_probe(self) -> None:
mock_adc.assert_not_called()
assert plugin._project is None

def test_api_key_omits_default_location(self) -> None:
"""Express mode (api_key) without location leaves location unset rather than defaulting to us-central1."""
with patch.dict(os.environ, {}, clear=True):
with patch('genkit_google_genai._google.genai.client.Client'):
plugin = VertexAI(api_key='k')
assert plugin._location is None
assert plugin._client_kwargs['location'] is None

def test_explicit_project_skips_adc_probe(self) -> None:
"""An explicit project short-circuits the ADC probe."""
with patch.dict(os.environ, {}, clear=True):
Expand Down
Loading