From 970deb0e3eb84523e1ec7c2383c8dceeba6f5230 Mon Sep 17 00:00:00 2001 From: ayam04 Date: Thu, 2 Oct 2025 03:26:38 +0530 Subject: [PATCH 1/2] fix: LiteLLM model override --- src/google/adk/models/lite_llm.py | 2 +- tests/unittests/models/test_litellm.py | 67 ++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/src/google/adk/models/lite_llm.py b/src/google/adk/models/lite_llm.py index d8b4d7ce81..080bf30b50 100644 --- a/src/google/adk/models/lite_llm.py +++ b/src/google/adk/models/lite_llm.py @@ -818,7 +818,7 @@ async def generate_content_async( tools = None completion_args = { - "model": self.model, + "model": llm_request.model or self.model, "messages": messages, "tools": tools, "response_format": response_format, diff --git a/tests/unittests/models/test_litellm.py b/tests/unittests/models/test_litellm.py index 84fd7f26d0..e527820f44 100644 --- a/tests/unittests/models/test_litellm.py +++ b/tests/unittests/models/test_litellm.py @@ -548,6 +548,73 @@ async def test_generate_content_async(mock_acompletion, lite_llm_instance): ) +@pytest.mark.asyncio +async def test_generate_content_async_with_model_override( + mock_acompletion, lite_llm_instance +): + llm_request = LlmRequest( + model="overridden_model", + contents=[ + types.Content( + role="user", parts=[types.Part.from_text(text="Test prompt")] + ) + ], + config=types.GenerateContentConfig( + tools=[ + types.Tool( + function_declarations=[ + types.FunctionDeclaration( + name="test_function", + description="Test function description", + parameters=types.Schema( + type=types.Type.OBJECT, + properties={ + "test_arg": types.Schema( + type=types.Type.STRING + ) + }, + ), + ) + ] + ) + ], + ), + ) + + async for response in lite_llm_instance.generate_content_async(llm_request): + assert response.content.role == "model" + assert response.content.parts[0].text == "Test response" + + mock_acompletion.assert_called_once() + + _, kwargs = mock_acompletion.call_args + assert kwargs["model"] == "overridden_model" + assert kwargs["messages"][0]["role"] == "user" + assert kwargs["messages"][0]["content"] == "Test prompt" + + +@pytest.mark.asyncio +async def test_generate_content_async_without_model_override( + mock_acompletion, lite_llm_instance +): + llm_request = LlmRequest( + model=None, + contents=[ + types.Content( + role="user", parts=[types.Part.from_text(text="Test prompt")] + ) + ], + ) + + async for response in lite_llm_instance.generate_content_async(llm_request): + assert response.content.role == "model" + + mock_acompletion.assert_called_once() + + _, kwargs = mock_acompletion.call_args + assert kwargs["model"] == "test_model" + + litellm_append_user_content_test_cases = [ pytest.param( LlmRequest( From f9d27308658df21b5c22e1a76229a26ac71dff05 Mon Sep 17 00:00:00 2001 From: ayam04 Date: Thu, 2 Oct 2025 03:42:39 +0530 Subject: [PATCH 2/2] fix: model override test complexity --- tests/unittests/models/test_litellm.py | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/tests/unittests/models/test_litellm.py b/tests/unittests/models/test_litellm.py index e527820f44..a47506b71d 100644 --- a/tests/unittests/models/test_litellm.py +++ b/tests/unittests/models/test_litellm.py @@ -559,26 +559,6 @@ async def test_generate_content_async_with_model_override( role="user", parts=[types.Part.from_text(text="Test prompt")] ) ], - config=types.GenerateContentConfig( - tools=[ - types.Tool( - function_declarations=[ - types.FunctionDeclaration( - name="test_function", - description="Test function description", - parameters=types.Schema( - type=types.Type.OBJECT, - properties={ - "test_arg": types.Schema( - type=types.Type.STRING - ) - }, - ), - ) - ] - ) - ], - ), ) async for response in lite_llm_instance.generate_content_async(llm_request):