Skip to content

Commit 8b97318

Browse files
GWealecopybara-github
authored andcommitted
test: Update LiteLLM finish_reason unmapped test
The previous test for unmapped LiteLLM finish_reason values was ineffective because LiteLLM's internal models normalize certain values (e.g., "eos" to "stop") before ADK processes them Co-authored-by: George Weale <gweale@google.com> PiperOrigin-RevId: 884678119
1 parent e6476c9 commit 8b97318

1 file changed

Lines changed: 20 additions & 13 deletions

File tree

tests/unittests/models/test_litellm.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import unittest
2323
from unittest.mock import ANY
2424
from unittest.mock import AsyncMock
25+
from unittest.mock import MagicMock
2526
from unittest.mock import Mock
2627
import warnings
2728

@@ -4388,19 +4389,25 @@ async def test_finish_reason_unknown_maps_to_other(
43884389
mock_acompletion, lite_llm_instance
43894390
):
43904391
"""Test that unmapped finish_reason values map to FinishReason.OTHER."""
4391-
mock_response = ModelResponse(
4392-
choices=[
4393-
Choices(
4394-
message=ChatCompletionAssistantMessage(
4395-
role="assistant",
4396-
content="Test response",
4397-
),
4398-
# LiteLLM validates finish_reason to a known set. Use a value that
4399-
# LiteLLM accepts but ADK does not explicitly map.
4400-
finish_reason="eos",
4401-
)
4402-
]
4403-
)
4392+
# LiteLLM's Choices model normalizes finish_reason values (e.g., "eos" ->
4393+
# "stop") before ADK processes them. To test ADK's own fallback mapping,
4394+
# construct a mock response that bypasses LiteLLM's normalization and
4395+
# returns a raw unmapped finish_reason string.
4396+
mock_choice = MagicMock()
4397+
mock_choice.get = lambda key, default=None: {
4398+
"message": ChatCompletionAssistantMessage(
4399+
role="assistant",
4400+
content="Test response",
4401+
),
4402+
"finish_reason": "totally_unknown_reason",
4403+
}.get(key, default)
4404+
4405+
mock_response = MagicMock()
4406+
mock_response.get = lambda key, default=None: {
4407+
"choices": [mock_choice],
4408+
}.get(key, default)
4409+
mock_response.model = "test_model"
4410+
44044411
mock_acompletion.return_value = mock_response
44054412

44064413
llm_request = LlmRequest(

0 commit comments

Comments
 (0)