From 57ab2cc9da833120b82b076f730db7c44619109e Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 6 Dec 2023 09:20:53 -0800 Subject: [PATCH] Revert "implement deployment id" This reverts commit b107db98fa796eef49df4254344d84543f2300e3. --- aider/coders/base_coder.py | 2 +- aider/history.py | 2 +- aider/main.py | 5 ++--- aider/models/model.py | 4 ++-- aider/models/openai.py | 3 +-- aider/repo.py | 2 +- aider/sendchat.py | 11 +++-------- tests/test_sendchat.py | 5 ++--- 8 files changed, 13 insertions(+), 21 deletions(-) diff --git a/aider/coders/base_coder.py b/aider/coders/base_coder.py index 7821ac202..4c9f8eca9 100755 --- a/aider/coders/base_coder.py +++ b/aider/coders/base_coder.py @@ -589,7 +589,7 @@ class Coder: def send(self, messages, model=None, functions=None): if not model: - model = self.main_model + model = self.main_model.name self.partial_response_content = "" self.partial_response_function_call = dict() diff --git a/aider/history.py b/aider/history.py index 9fdaf9c14..d1ee70ede 100644 --- a/aider/history.py +++ b/aider/history.py @@ -85,7 +85,7 @@ class ChatSummary: dict(role="user", content=content), ] - summary = simple_send_with_retries(self.client, self.model, messages) + summary = simple_send_with_retries(self.client, self.model.name, messages) if summary is None: raise ValueError(f"summarizer unexpectedly failed for {self.model.name}") summary = prompts.summary_prefix + summary diff --git a/aider/main.py b/aider/main.py index 63ed0753d..d4c8cb5c7 100644 --- a/aider/main.py +++ b/aider/main.py @@ -189,6 +189,7 @@ def main(argv=None, input=None, output=None, force_git_root=None): metavar="OPENAI_API_VERSION", help="Specify the api_version", ) + # TODO: use deployment_id model_group.add_argument( "--openai-api-deployment-id", metavar="OPENAI_API_DEPLOYMENT_ID", @@ -506,9 +507,7 @@ def main(argv=None, input=None, output=None, force_git_root=None): client = openai.OpenAI(api_key=args.openai_api_key, **kwargs) - main_model = models.Model.create( - args.model, client, deployment_id=args.openai_api_deployment_id - ) + main_model = models.Model.create(args.model, client) try: coder = Coder.create( diff --git a/aider/models/model.py b/aider/models/model.py index 7eb3be88c..70f09d313 100644 --- a/aider/models/model.py +++ b/aider/models/model.py @@ -16,13 +16,13 @@ class Model: completion_price = None @classmethod - def create(cls, name, client=None, deployment_id=None): + def create(cls, name, client=None): from .openai import OpenAIModel from .openrouter import OpenRouterModel if client and client.base_url.host == "openrouter.ai": return OpenRouterModel(client, name) - return OpenAIModel(name, deployment_id=deployment_id) + return OpenAIModel(name) def __str__(self): return self.name diff --git a/aider/models/openai.py b/aider/models/openai.py index 435048868..1c6286d63 100644 --- a/aider/models/openai.py +++ b/aider/models/openai.py @@ -13,9 +13,8 @@ known_tokens = { class OpenAIModel(Model): - def __init__(self, name, deployment_id=None): + def __init__(self, name): self.name = name - self.deployment_id = deployment_id tokens = None diff --git a/aider/repo.py b/aider/repo.py index 7fd096984..6943c5568 100644 --- a/aider/repo.py +++ b/aider/repo.py @@ -119,7 +119,7 @@ class GitRepo: ] for model in models.Model.commit_message_models(): - commit_message = simple_send_with_retries(self.client, model, messages) + commit_message = simple_send_with_retries(self.client, model.name, messages) if commit_message: break diff --git a/aider/sendchat.py b/aider/sendchat.py index baba6e682..c770ef087 100644 --- a/aider/sendchat.py +++ b/aider/sendchat.py @@ -28,15 +28,10 @@ CACHE = None f"{details.get('exception','Exception')}\nRetry in {details['wait']:.1f} seconds." ), ) -def send_with_retries(client, model, messages, functions, stream): +def send_with_retries(client, model_name, messages, functions, stream): if not client: raise ValueError("No openai client provided") - if model.deployment_id: - model_name = model.deployment_id - else: - model_name = model.name - kwargs = dict( model=model_name, messages=messages, @@ -62,11 +57,11 @@ def send_with_retries(client, model, messages, functions, stream): return hash_object, res -def simple_send_with_retries(client, model, messages): +def simple_send_with_retries(client, model_name, messages): try: _hash, response = send_with_retries( client=client, - model=model, + model_name=model_name, messages=messages, functions=None, stream=False, diff --git a/tests/test_sendchat.py b/tests/test_sendchat.py index 2613d1f3a..7bb8fcfab 100644 --- a/tests/test_sendchat.py +++ b/tests/test_sendchat.py @@ -4,7 +4,6 @@ from unittest.mock import MagicMock, patch import httpx import openai -from aider.models import Model from aider.sendchat import send_with_retries @@ -28,7 +27,7 @@ class TestSendChat(unittest.TestCase): ] # Call the send_with_retries method - send_with_retries(mock_client, Model.weak_model(), ["message"], None, False) + send_with_retries(mock_client, "model", ["message"], None, False) mock_print.assert_called_once() @patch("aider.sendchat.openai.ChatCompletion.create") @@ -43,5 +42,5 @@ class TestSendChat(unittest.TestCase): ] # Call the send_with_retries method - send_with_retries(mock_client, Model.weak_model(), ["message"], None, False) + send_with_retries(mock_client, "model", ["message"], None, False) mock_print.assert_called_once()