mirror of
https://github.com/encounter/adk-python.git
synced 2026-07-09 18:19:28 -07:00
chore: Add warning for using Gemini models via LiteLLM
Recommend to use Gemini outside of LiteLLM PiperOrigin-RevId: 800971705
This commit is contained in:
committed by
Copybara-Service
parent
fcd748e17f
commit
9291daaa8e
@@ -16,6 +16,7 @@
|
||||
import json
|
||||
from unittest.mock import AsyncMock
|
||||
from unittest.mock import Mock
|
||||
import warnings
|
||||
|
||||
from google.adk.models.lite_llm import _content_to_message_param
|
||||
from google.adk.models.lite_llm import _function_declaration_to_tool_param
|
||||
@@ -1574,3 +1575,51 @@ def test_get_completion_inputs_generation_params():
|
||||
# Should not include max_output_tokens
|
||||
assert "max_output_tokens" not in generation_params
|
||||
assert "stop_sequences" not in generation_params
|
||||
|
||||
|
||||
def test_gemini_via_litellm_warning(monkeypatch):
|
||||
"""Test that Gemini via LiteLLM shows warning."""
|
||||
# Ensure environment variable is not set
|
||||
monkeypatch.delenv("ADK_SUPPRESS_GEMINI_LITELLM_WARNINGS", raising=False)
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter("always")
|
||||
# Test with Google AI Studio Gemini via LiteLLM
|
||||
LiteLlm(model="gemini/gemini-2.5-pro-exp-03-25")
|
||||
assert len(w) == 1
|
||||
assert issubclass(w[0].category, UserWarning)
|
||||
assert "[GEMINI_VIA_LITELLM]" in str(w[0].message)
|
||||
assert "better performance" in str(w[0].message)
|
||||
assert "gemini-2.5-pro-exp-03-25" in str(w[0].message)
|
||||
assert "ADK_SUPPRESS_GEMINI_LITELLM_WARNINGS" in str(w[0].message)
|
||||
|
||||
|
||||
def test_gemini_via_litellm_warning_vertex_ai(monkeypatch):
|
||||
"""Test that Vertex AI Gemini via LiteLLM shows warning."""
|
||||
# Ensure environment variable is not set
|
||||
monkeypatch.delenv("ADK_SUPPRESS_GEMINI_LITELLM_WARNINGS", raising=False)
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter("always")
|
||||
# Test with Vertex AI Gemini via LiteLLM
|
||||
LiteLlm(model="vertex_ai/gemini-1.5-flash")
|
||||
assert len(w) == 1
|
||||
assert issubclass(w[0].category, UserWarning)
|
||||
assert "[GEMINI_VIA_LITELLM]" in str(w[0].message)
|
||||
assert "vertex_ai/gemini-1.5-flash" in str(w[0].message)
|
||||
|
||||
|
||||
def test_gemini_via_litellm_warning_suppressed(monkeypatch):
|
||||
"""Test that Gemini via LiteLLM warning can be suppressed."""
|
||||
monkeypatch.setenv("ADK_SUPPRESS_GEMINI_LITELLM_WARNINGS", "true")
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter("always")
|
||||
LiteLlm(model="gemini/gemini-2.5-pro-exp-03-25")
|
||||
assert len(w) == 0
|
||||
|
||||
|
||||
def test_non_gemini_litellm_no_warning():
|
||||
"""Test that non-Gemini models via LiteLLM don't show warning."""
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter("always")
|
||||
# Test with non-Gemini model
|
||||
LiteLlm(model="openai/gpt-4o")
|
||||
assert len(w) == 0
|
||||
|
||||
Reference in New Issue
Block a user