You've already forked adk-python
mirror of
https://github.com/encounter/adk-python.git
synced 2026-03-30 10:57:20 -07:00
fix: Support models slash prefix in model name extraction
Support "models/" prefix in model name extraction PiperOrigin-RevId: 827557443
This commit is contained in:
committed by
Copybara-Service
parent
92a7d19573
commit
8dff85099d
@@ -27,8 +27,8 @@ def extract_model_name(model_string: str) -> str:
|
||||
"""Extract the actual model name from either simple or path-based format.
|
||||
|
||||
Args:
|
||||
model_string: Either a simple model name like "gemini-2.5-pro" or
|
||||
a path-based model name like "projects/.../models/gemini-2.0-flash-001"
|
||||
model_string: Either a simple model name like "gemini-2.5-pro" or a
|
||||
path-based model name like "projects/.../models/gemini-2.0-flash-001"
|
||||
|
||||
Returns:
|
||||
The extracted model name (e.g., "gemini-2.5-pro")
|
||||
@@ -41,6 +41,10 @@ def extract_model_name(model_string: str) -> str:
|
||||
if match:
|
||||
return match.group(1)
|
||||
|
||||
# Handle 'models/' prefixed names like "models/gemini-2.5-pro"
|
||||
if model_string.startswith('models/'):
|
||||
return model_string[len('models/') :]
|
||||
|
||||
# If it's not a path-based model, return as-is (simple model name)
|
||||
return model_string
|
||||
|
||||
|
||||
@@ -42,6 +42,11 @@ class TestExtractModelName:
|
||||
path_model_3 = 'projects/test-project/locations/europe-west1/publishers/google/models/claude-3-sonnet'
|
||||
assert extract_model_name(path_model_3) == 'claude-3-sonnet'
|
||||
|
||||
def test_extract_model_name_with_models_prefix(self):
|
||||
"""Test extraction of model names with 'models/' prefix."""
|
||||
assert extract_model_name('models/gemini-2.5-pro') == 'gemini-2.5-pro'
|
||||
assert extract_model_name('models/gemini-1.5-flash') == 'gemini-1.5-flash'
|
||||
|
||||
def test_extract_model_name_invalid_path(self):
|
||||
"""Test that invalid path formats return the original string."""
|
||||
invalid_paths = [
|
||||
|
||||
Reference in New Issue
Block a user