Skip to content
Open
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
20 changes: 9 additions & 11 deletions src/google/adk/models/lite_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@
# 1. FinishReason.TOOL_CALL enum does not exist (as of google-genai 0.8.0)
# 2. Tool calls represent normal completion (model stopped to invoke tools)
# 3. Gemini native responses use STOP for tool calls (see lite_llm.py:910)
# 4. Mapping tool-related finish reasons to STOP preserves backward
# compatibility with existing ADK consumers that assume STOP
# indicates a successful, non-error completion.
_FINISH_REASON_MAPPING = {
"length": types.FinishReason.MAX_TOKENS,
"stop": types.FinishReason.STOP,
Expand Down Expand Up @@ -131,6 +134,10 @@
"before a response was recorded)."
)

_FALLBACK_USER_CONTENT_TEXT = (
"Handle the incoming request according to the provided requirements."
)

_LITELLM_IMPORTED = False
_LITELLM_GLOBAL_SYMBOLS = (
"ChatCompletionAssistantMessage",
Expand Down Expand Up @@ -489,22 +496,13 @@ def _append_fallback_user_content_if_missing(
if not parts:
content.parts = []
content.parts.append(
types.Part.from_text(
text="Handle the requests as specified in the System Instruction."
)
types.Part.from_text(text=_FALLBACK_USER_CONTENT_TEXT)
)
return
llm_request.contents.append(
types.Content(
role="user",
parts=[
types.Part.from_text(
text=(
"Handle the requests as specified in the System"
" Instruction."
)
),
],
parts=[types.Part.from_text(text=_FALLBACK_USER_CONTENT_TEXT)],
)
)

Expand Down
8 changes: 3 additions & 5 deletions tests/unittests/models/test_litellm.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import warnings

from google.adk.models.lite_llm import _content_to_message_param
from google.adk.models.lite_llm import _FALLBACK_USER_CONTENT_TEXT
from google.adk.models.lite_llm import _FILE_ID_REQUIRED_PROVIDERS
from google.adk.models.lite_llm import _FINISH_REASON_MAPPING
from google.adk.models.lite_llm import _function_declaration_to_tool_param
Expand Down Expand Up @@ -978,16 +979,13 @@ async def test_generate_content_async_adds_fallback_user_message(
message for message in kwargs["messages"] if message["role"] == "user"
]
assert any(
message.get("content")
== "Handle the requests as specified in the System Instruction."
message.get("content") == _FALLBACK_USER_CONTENT_TEXT
for message in user_messages
)
assert (
sum(1 for content in llm_request.contents if content.role == "user") == 1
)
assert llm_request.contents[-1].parts[0].text == (
"Handle the requests as specified in the System Instruction."
)
assert llm_request.contents[-1].parts[0].text == _FALLBACK_USER_CONTENT_TEXT


litellm_append_user_content_test_cases = [
Expand Down
Loading