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
8 changes: 5 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ dependencies = [
"opentelemetry-api>=1.31.0, <2.0.0", # OpenTelemetry
"opentelemetry-exporter-gcp-trace>=1.9.0, <2.0.0",
"opentelemetry-sdk>=1.31.0, <2.0.0",
"packaging>=24.0, <25.0", # Version parsing in runtime guards
"pydantic>=2.0, <3.0.0", # For data validation/models
"python-dateutil>=2.9.0.post0, <3.0.0", # For Vertext AI Session Service
"python-dotenv>=1.0.0, <2.0.0", # To manage environment variables
Expand Down Expand Up @@ -102,9 +103,9 @@ test = [
"langchain-community>=0.3.17",
# langgraph 0.5 removed langgraph.graph.graph which we depend on
"langgraph>=0.2.60, <= 0.4.10", # For LangGraphAgent
"litellm>=1.75.5, <2.0.0", # For LiteLLM tests
"litellm>=1.75.5, <2.0.0", # For LiteLLM tests; upper-bounded due to OpenAI API coupling
"llama-index-readers-file>=0.4.0", # For retrieval tests
"openai<=1.99.9", # For LiteLLM
"openai<=1.99.9", # For LiteLLM; upper-bound to avoid breaking changes
"pytest-asyncio>=0.25.0",
"pytest-mock>=3.14.0",
"pytest-xdist>=3.6.1",
Expand All @@ -129,7 +130,8 @@ extensions = [
"crewai[tools];python_version>='3.10'", # For CrewaiTool
"docker>=7.0.0", # For ContainerCodeExecutor
"langgraph>=0.2.60", # For LangGraphAgent
"litellm>=1.75.5", # For LiteLlm class. Currently has OpenAI limitations. TODO: once LiteLlm fix it
"litellm>=1.75.5, <2.0.0", # For LiteLlm class. Upper-bounded due to OpenAI API coupling; TODO: relax once LiteLlm fixes it
"openai<=1.99.9", # For LiteLlm class. Upper-bound required due to LiteLlm/OpenAI breaking changes
"llama-index-readers-file>=0.4.0", # For retrieval using LlamaIndex.
"lxml>=5.3.0", # For load_web_page tool.
"toolbox-core>=0.1.0", # For tools.toolbox_toolset.ToolboxToolset
Expand Down
34 changes: 34 additions & 0 deletions src/google/adk/models/lite_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from __future__ import annotations

import base64
import importlib.metadata as im
import json
import logging
from typing import Any
Expand Down Expand Up @@ -50,6 +51,7 @@
from litellm import Message
from litellm import ModelResponse
from litellm import OpenAIMessageContent
from packaging.version import Version
from pydantic import BaseModel
from pydantic import Field
from typing_extensions import override
Expand All @@ -67,6 +69,37 @@
_EXCLUDED_PART_FIELD = {"inline_data": {"data"}}


def _assert_litellm_openai_compat() -> None:
"""Fail fast if installed litellm/openai versions are incompatible.

Policy:
- litellm < 2.0.0
- openai <= 1.99.9
"""

try:
litellm_version = im.version("litellm")
except Exception:
# If not installed, defer to import-time errors elsewhere
return

try:
openai_version = im.version("openai")
except Exception:
# If openai is not installed but user still tries to use LiteLLM with providers
# that require it, they will hit an import/runtime error later. No-op here.
return

if Version(litellm_version) >= Version("2.0.0"):
raise RuntimeError(
f"Unsupported litellm {litellm_version}; require < 2.0.0"
)
if Version(openai_version) > Version("1.99.9"):
raise RuntimeError(
f"Unsupported openai {openai_version}; require <= 1.99.9"
)


class FunctionChunk(BaseModel):
id: Optional[str]
name: Optional[str]
Expand Down Expand Up @@ -704,6 +737,7 @@ def __init__(self, model: str, **kwargs):
**kwargs: Additional arguments to pass to the litellm completion api.
"""
super().__init__(model=model, **kwargs)
_assert_litellm_openai_compat()
self._additional_args = kwargs
# preventing generation call with llm_client
# and overriding messages, tools and stream which are managed internally
Expand Down