diff --git a/aider/utils.py b/aider/utils.py index c2053e818..c9f41363f 100644 --- a/aider/utils.py +++ b/aider/utils.py @@ -12,6 +12,7 @@ def is_image_file(file_name): :param file_name: The name of the file to check. :return: True if the file is an image, False otherwise. """ + file_name = str(file_name) # Convert file_name to string return any(file_name.endswith(ext) for ext in IMAGE_EXTENSIONS) @@ -50,4 +51,6 @@ def is_gpt4_with_openai_base_url(model_name, client): :param client: The OpenAI client instance. :return: True if conditions are met, False otherwise. """ + if client is None or not hasattr(client, 'base_url'): + return False return model_name.startswith("gpt-4") and "api.openai.com" in client.base_url.host diff --git a/tests/test_models.py b/tests/test_models.py index fe8b681dc..6b2dc58ce 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -29,19 +29,19 @@ class TestModels(unittest.TestCase): def test_openrouter_model_properties(self): client = MagicMock() - client.models.list.return_value = { - "data": [ - { - "id": "openai/gpt-4", - "object": "model", - "context_length": "8192", - "pricing": {"prompt": "0.00006", "completion": "0.00012"}, - } - ] - } - client.models.list.return_value = type( - "", (), {"data": client.models.list.return_value["data"]} - )() + class ModelData: + def __init__(self, id, object, context_length, pricing): + self.id = id + self.object = object + self.context_length = context_length + self.pricing = pricing + + model_data = ModelData("openai/gpt-4", "model", "8192", {"prompt": "0.00006", "completion": "0.00012"}) + class ModelList: + def __init__(self, data): + self.data = data + + client.models.list.return_value = ModelList([model_data]) model = OpenRouterModel(client, "gpt-4") self.assertEqual(model.name, "openai/gpt-4")