Repository navigation
Expand file tree
/
Copy pathtest_models.py
More file actions
114 lines (97 loc) · 3.94 KB
/
Copy pathtest_models.py
File metadata and controls
114 lines (97 loc) · 3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from google.adk import models
from google.adk.models.anthropic_llm import Claude
from google.adk.models.google_llm import Gemini
from google.adk.models.lite_llm import LiteLlm
import pytest
@pytest.mark.parametrize(
'model_name',
[
'gemini-1.5-flash',
'gemini-1.5-flash-001',
'gemini-1.5-flash-002',
'gemini-1.5-pro',
'gemini-1.5-pro-001',
'gemini-1.5-pro-002',
'gemini-2.0-flash-exp',
'projects/123456/locations/us-central1/endpoints/123456', # finetuned vertex gemini endpoint
'projects/123456/locations/us-central1/publishers/google/models/gemini-2.0-flash-exp', # vertex gemini long name
],
)
def test_match_gemini_family(model_name):
"""Test that Gemini models are resolved correctly."""
assert models.LLMRegistry.resolve(model_name) is Gemini
@pytest.mark.parametrize(
'model_name',
[
'claude-3-5-haiku@20241022',
'claude-3-5-sonnet-v2@20241022',
'claude-3-5-sonnet@20240620',
'claude-3-haiku@20240307',
'claude-3-opus@20240229',
'claude-3-sonnet@20240229',
'claude-sonnet-4@20250514',
'claude-opus-4@20250514',
],
)
def test_match_claude_family(model_name):
"""Test that Claude models are resolved correctly."""
assert models.LLMRegistry.resolve(model_name) is Claude
@pytest.mark.parametrize(
'model_name',
[
'openai/gpt-4o',
'openai/gpt-4o-mini',
'groq/llama3-70b-8192',
'groq/mixtral-8x7b-32768',
'anthropic/claude-3-opus-20240229',
'anthropic/claude-3-5-sonnet-20241022',
],
)
def test_match_litellm_family(model_name):
"""Test that LiteLLM models are resolved correctly."""
assert models.LLMRegistry.resolve(model_name) is LiteLlm
def test_non_exist_model():
with pytest.raises(ValueError) as e_info:
models.LLMRegistry.resolve('non-exist-model')
assert 'Model non-exist-model not found.' in str(e_info.value)
def test_helpful_error_for_claude_without_extensions():
"""Test that missing Claude models show helpful install instructions.
Note: This test may pass even when anthropic IS installed, because it
only checks the error message format when a model is not found.
"""
# Use a non-existent Claude model variant to trigger error
with pytest.raises(ValueError) as e_info:
models.LLMRegistry.resolve('claude-nonexistent-model-xyz')
error_msg = str(e_info.value)
# The error should mention anthropic package and installation instructions
# These checks work whether or not anthropic is actually installed
assert 'Model claude-nonexistent-model-xyz not found' in error_msg
assert 'anthropic package' in error_msg
assert 'pip install' in error_msg
def test_helpful_error_for_litellm_without_extensions():
"""Test that missing LiteLLM models show helpful install instructions.
Note: This test may pass even when litellm IS installed, because it
only checks the error message format when a model is not found.
"""
# Use a non-existent provider to trigger error
with pytest.raises(ValueError) as e_info:
models.LLMRegistry.resolve('unknown-provider/gpt-4o')
error_msg = str(e_info.value)
# The error should mention litellm package for provider-style models
assert 'Model unknown-provider/gpt-4o not found' in error_msg
assert 'litellm package' in error_msg
assert 'pip install' in error_msg
assert 'Provider-style models' in error_msg