diff --git a/tests/basic/test_models.py b/tests/basic/test_models.py index 9a263a29d..9f86b4749 100644 --- a/tests/basic/test_models.py +++ b/tests/basic/test_models.py @@ -329,65 +329,7 @@ class TestModels(unittest.TestCase): self.assertEqual(model.editor_edit_format, "editor-diff") self.assertTrue(model.use_repo_map) - def test_remove_reasoning_content(self): - # Test with no removal configured - model = Model("gpt-4") - text = "Here is some reasoning and regular text" - self.assertEqual(model.remove_reasoning_content(text), text) - # Test with removal configured - model = Model("deepseek-r1") # This model has remove_reasoning="think" - text = """Here is some text - -This is reasoning that should be removed -Over multiple lines - -And more text here""" - expected = """Here is some text - -And more text here""" - self.assertEqual(model.remove_reasoning_content(text), expected) - - # Test with multiple reasoning blocks - text = """Start -Block 1 -Middle -Block 2 -End""" - expected = """Start - -Middle - -End""" - self.assertEqual(model.remove_reasoning_content(text), expected) - - # Test with no reasoning blocks - text = "Just regular text" - self.assertEqual(model.remove_reasoning_content(text), text) - - @patch("aider.models.litellm.completion") - def test_simple_send_with_retries_removes_reasoning(self, mock_completion): - model = Model("deepseek-r1") # This model has remove_reasoning="think" - - # Mock the completion response - mock_response = MagicMock() - mock_response.choices = [MagicMock(message=MagicMock(content="""Here is some text - -This reasoning should be removed - -And this text should remain"""))] - mock_completion.return_value = mock_response - - messages = [{"role": "user", "content": "test"}] - result = model.simple_send_with_retries(messages) - - expected = """Here is some text - -And this text should remain""" - self.assertEqual(result, expected) - - # Verify the completion was called - mock_completion.assert_called_once() def test_aider_extra_model_settings(self): import tempfile diff --git a/tests/basic/test_reasoning.py b/tests/basic/test_reasoning.py index fd44af80d..bb6d6ce43 100644 --- a/tests/basic/test_reasoning.py +++ b/tests/basic/test_reasoning.py @@ -5,6 +5,7 @@ from aider.coders.base_coder import Coder from aider.dump import dump # noqa from aider.io import InputOutput from aider.models import Model +from aider.reasoning_tags import remove_reasoning_content class TestReasoning(unittest.TestCase): @@ -341,6 +342,66 @@ class TestReasoning(unittest.TestCase): reasoning_pos, main_pos, "Reasoning content should appear before main content" ) + def test_remove_reasoning_content(self): + """Test the remove_reasoning_content function from reasoning_tags module.""" + # Test with no removal configured + text = "Here is some reasoning and regular text" + self.assertEqual(remove_reasoning_content(text, None), text) + + # Test with removal configured + text = """Here is some text + +This is reasoning that should be removed +Over multiple lines + +And more text here""" + expected = """Here is some text + +And more text here""" + self.assertEqual(remove_reasoning_content(text, "think"), expected) + + # Test with multiple reasoning blocks + text = """Start +Block 1 +Middle +Block 2 +End""" + expected = """Start + +Middle + +End""" + self.assertEqual(remove_reasoning_content(text, "think"), expected) + + # Test with no reasoning blocks + text = "Just regular text" + self.assertEqual(remove_reasoning_content(text, "think"), text) + + @patch("aider.models.litellm.completion") + def test_simple_send_with_retries_removes_reasoning(self, mock_completion): + """Test that simple_send_with_retries correctly removes reasoning content.""" + model = Model("deepseek-r1") # This model has remove_reasoning="think" + + # Mock the completion response + mock_response = MagicMock() + mock_response.choices = [MagicMock(message=MagicMock(content="""Here is some text + +This reasoning should be removed + +And this text should remain"""))] + mock_completion.return_value = mock_response + + messages = [{"role": "user", "content": "test"}] + result = model.simple_send_with_retries(messages) + + expected = """Here is some text + +And this text should remain""" + self.assertEqual(result, expected) + + # Verify the completion was called + mock_completion.assert_called_once() + if __name__ == "__main__": unittest.main()