mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-21 12:55:00 +00:00
83 lines
2.8 KiB
Python
83 lines
2.8 KiB
Python
import unittest
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
from aider.models import Model, get_model_info, sanity_check_model, sanity_check_models
|
|
|
|
|
|
class TestModels(unittest.TestCase):
|
|
def test_get_model_info_nonexistent(self):
|
|
info = get_model_info("non-existent-model")
|
|
self.assertEqual(info, {})
|
|
|
|
def test_max_context_tokens(self):
|
|
model = Model("gpt-3.5-turbo")
|
|
self.assertEqual(model.info["max_input_tokens"], 16385)
|
|
|
|
model = Model("gpt-3.5-turbo-16k")
|
|
self.assertEqual(model.info["max_input_tokens"], 16385)
|
|
|
|
model = Model("gpt-3.5-turbo-1106")
|
|
self.assertEqual(model.info["max_input_tokens"], 16385)
|
|
|
|
model = Model("gpt-4")
|
|
self.assertEqual(model.info["max_input_tokens"], 8 * 1024)
|
|
|
|
model = Model("gpt-4-32k")
|
|
self.assertEqual(model.info["max_input_tokens"], 32 * 1024)
|
|
|
|
model = Model("gpt-4-0613")
|
|
self.assertEqual(model.info["max_input_tokens"], 8 * 1024)
|
|
|
|
@patch("os.environ")
|
|
def test_sanity_check_model_all_set(self, mock_environ):
|
|
mock_environ.get.return_value = "dummy_value"
|
|
mock_io = MagicMock()
|
|
model = MagicMock()
|
|
model.name = "test-model"
|
|
model.missing_keys = ["API_KEY1", "API_KEY2"]
|
|
model.keys_in_environment = True
|
|
model.info = {"some": "info"}
|
|
|
|
sanity_check_model(mock_io, model)
|
|
|
|
mock_io.tool_output.assert_called()
|
|
calls = mock_io.tool_output.call_args_list
|
|
self.assertIn("- API_KEY1: Set", str(calls))
|
|
self.assertIn("- API_KEY2: Set", str(calls))
|
|
|
|
@patch("os.environ")
|
|
def test_sanity_check_model_not_set(self, mock_environ):
|
|
mock_environ.get.return_value = ""
|
|
mock_io = MagicMock()
|
|
model = MagicMock()
|
|
model.name = "test-model"
|
|
model.missing_keys = ["API_KEY1", "API_KEY2"]
|
|
model.keys_in_environment = True
|
|
model.info = {"some": "info"}
|
|
|
|
sanity_check_model(mock_io, model)
|
|
|
|
mock_io.tool_output.assert_called()
|
|
calls = mock_io.tool_output.call_args_list
|
|
self.assertIn("- API_KEY1: Not set", str(calls))
|
|
self.assertIn("- API_KEY2: Not set", str(calls))
|
|
|
|
def test_sanity_check_models_bogus_editor(self):
|
|
mock_io = MagicMock()
|
|
main_model = Model("gpt-4")
|
|
main_model.editor_model = Model("bogus-model")
|
|
|
|
result = sanity_check_models(mock_io, main_model)
|
|
|
|
self.assertTrue(
|
|
result
|
|
) # Should return True because there's a problem with the editor model
|
|
mock_io.tool_warning.assert_called_once() # Ensure a warning was issued
|
|
warning_message = mock_io.tool_warning.call_args[0][0]
|
|
self.assertIn(
|
|
"bogus-model", warning_message
|
|
) # Check that the warning mentions the bogus model
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|