mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-22 05:14:59 +00:00
feat: Add test for reasoning content formatting in Coder.send() method
This commit is contained in:
parent
f7d18ef976
commit
2ffe49130d
1 changed files with 59 additions and 0 deletions
|
@ -0,0 +1,59 @@
|
|||
import unittest
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from aider.coders.base_coder import Coder
|
||||
from aider.io import InputOutput
|
||||
from aider.models import Model
|
||||
from aider.reasoning_tags import REASONING_TAG, format_reasoning_content, replace_reasoning_tags
|
||||
|
||||
|
||||
class TestReasoning(unittest.TestCase):
|
||||
def test_send_with_reasoning_content(self):
|
||||
"""Test that reasoning content is properly formatted and output."""
|
||||
# Setup IO with no streaming, no pretty
|
||||
io = InputOutput(pretty=False, stream=False)
|
||||
io.ai_output = MagicMock()
|
||||
|
||||
# Setup model and coder
|
||||
model = Model("gpt-3.5-turbo")
|
||||
coder = Coder.create(model, None, io=io)
|
||||
|
||||
# Test data
|
||||
reasoning_content = "My step-by-step reasoning process"
|
||||
main_content = "Final answer after reasoning"
|
||||
|
||||
# Mock completion response with reasoning content
|
||||
class MockCompletion:
|
||||
def __init__(self, content, reasoning_content):
|
||||
self.content = content
|
||||
self.reasoning_content = reasoning_content
|
||||
|
||||
mock_completion = MockCompletion(main_content, reasoning_content)
|
||||
|
||||
# Mock the model's send_completion method
|
||||
with patch.object(model, 'send_completion', return_value=mock_completion):
|
||||
# Call send with a simple message
|
||||
messages = [{"role": "user", "content": "test prompt"}]
|
||||
coder.send(messages)
|
||||
|
||||
# Check if ai_output was called with formatted content
|
||||
io.ai_output.assert_called_once()
|
||||
output = io.ai_output.call_args[0][0]
|
||||
|
||||
# Output should contain formatted reasoning tags
|
||||
self.assertIn("Thinking ...", output)
|
||||
self.assertIn("... done thinking", output)
|
||||
|
||||
# Output should include both reasoning and main content
|
||||
self.assertIn(reasoning_content, output)
|
||||
self.assertIn(main_content, output)
|
||||
|
||||
# Ensure proper order: reasoning first, then main content
|
||||
reasoning_pos = output.find(reasoning_content)
|
||||
main_pos = output.find(main_content)
|
||||
self.assertLess(reasoning_pos, main_pos,
|
||||
"Reasoning content should appear before main content")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
Loading…
Add table
Add a link
Reference in a new issue