Skip to content

Commit a9b853f

Browse files
google-genai-botcopybara-github
authored andcommitted
fix: ApigeeLLM support for Built-in tools like GoogleSearch, BuiltInCodeExecutor when calling Gemini models through Apigee
PiperOrigin-RevId: 840459113
1 parent 3d444cc commit a9b853f

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

src/google/adk/utils/model_name_utils.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,17 @@ def extract_model_name(model_string: str) -> str:
3434
The extracted model name (e.g., "gemini-2.5-pro")
3535
"""
3636
# Pattern for path-based model names
37-
path_pattern = (
38-
r'^projects/[^/]+/locations/[^/]+/publishers/[^/]+/models/(.+)$'
37+
# Need to support both Vertex/Gemini and Apigee model paths.
38+
path_patterns = (
39+
r'^projects/[^/]+/locations/[^/]+/publishers/[^/]+/models/(.+)$',
40+
r'^apigee/(?:[^/]+/)?(?:[^/]+/)?(.+)$',
3941
)
40-
match = re.match(path_pattern, model_string)
41-
if match:
42-
return match.group(1)
42+
# Check against all path-based patterns
43+
for pattern in path_patterns:
44+
match = re.match(pattern, model_string)
45+
if match:
46+
# Return the captured group (the model name)
47+
return match.group(1)
4348

4449
# Handle 'models/' prefixed names like "models/gemini-2.5-pro"
4550
if model_string.startswith('models/'):

tests/unittests/utils/test_model_name_utils.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,24 @@ def test_extract_model_name_path_based_model(self):
4242
path_model_3 = 'projects/test-project/locations/europe-west1/publishers/google/models/claude-3-sonnet'
4343
assert extract_model_name(path_model_3) == 'claude-3-sonnet'
4444

45+
path_model_4 = 'apigee/gemini-2.5-flash'
46+
assert extract_model_name(path_model_4) == 'gemini-2.5-flash'
47+
48+
path_model_5 = 'apigee/v1/gemini-2.5-flash'
49+
assert extract_model_name(path_model_5) == 'gemini-2.5-flash'
50+
51+
path_model_6 = 'apigee/gemini/gemini-2.5-flash'
52+
assert extract_model_name(path_model_6) == 'gemini-2.5-flash'
53+
54+
path_model_7 = 'apigee/vertex_ai/gemini-2.5-flash'
55+
assert extract_model_name(path_model_7) == 'gemini-2.5-flash'
56+
57+
path_model_8 = 'apigee/gemini/v1/gemini-2.5-flash'
58+
assert extract_model_name(path_model_8) == 'gemini-2.5-flash'
59+
60+
path_model_9 = 'apigee/vertex_ai/v1beta/gemini-2.5-flash'
61+
assert extract_model_name(path_model_9) == 'gemini-2.5-flash'
62+
4563
def test_extract_model_name_with_models_prefix(self):
4664
"""Test extraction of model names with 'models/' prefix."""
4765
assert extract_model_name('models/gemini-2.5-pro') == 'gemini-2.5-pro'

0 commit comments

Comments
 (0)