From ded61b793457ee733f0a981bf0f8a8804761b726 Mon Sep 17 00:00:00 2001 From: Jay Date: Sat, 18 Jul 2026 00:29:33 +0000 Subject: [PATCH] test(smolagents): add regression test for issue #1972 Ref: #1972 Signed-off-by: Jay --- tests/test_issue_1972.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tests/test_issue_1972.py diff --git a/tests/test_issue_1972.py b/tests/test_issue_1972.py new file mode 100644 index 000000000..d0b3356b7 --- /dev/null +++ b/tests/test_issue_1972.py @@ -0,0 +1,28 @@ +from unittest.mock import MagicMock, patch + +from smolagents.models import LiteLLMModel + + +def test_issue_1972(): + mock_litellm = MagicMock() + mock_response = MagicMock() + mock_response.choices = [MagicMock()] + mock_response.choices[0].message.role = "assistant" + mock_response.choices[0].message.content = "FOO.BAR" + mock_response.choices[0].message.tool_calls = None + mock_response.usage.prompt_tokens = 10 + mock_response.usage.completion_tokens = 5 + mock_litellm.completion.return_value = mock_response + + messages = [ + {"role": "system", "content": "When you say anything Start with 'FOO'"}, + {"role": "system", "content": "When you say anything End with 'BAR'"}, + {"role": "user", "content": "Just say '.'"}, + ] + + with patch("smolagents.models.LiteLLMModel.create_client", return_value=mock_litellm): + model = LiteLLMModel(model_id="gemini/gemini-2.5-flash", api_key="test_api_key") + response = model(messages) + + assert response.content == "FOO.BAR" + assert mock_litellm.completion.call_count == 1