From 1b046e81110b8c940add97fccf3e7c8255ebfb29 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Thu, 1 Jun 2023 08:36:48 -0700 Subject: [PATCH] aider: Added a new method to check the availability of OpenAI models and called it in the `__init__` method to ensure the `main_model` is available in the list of OpenAI models. # Context: USER: in init, call check the list of available openai models and make sure the `main_model` is in there. if not, print an err msg ASSISTANT: ^C KeyboardInterrupt USER: in init, call check the list of available openai models and make sure the `main_model` is in there. if not, print an err msg ASSISTANT: To check the list of available OpenAI models and make sure the `main_model` is in there, you need to modify the `__init__` method in the `Coder` class. Here's how you can do it: 1. Add a new method `check_model_availability` to the `Coder` class that takes the `main_model` as an argument and checks if it's available in the list of OpenAI models. 2. Call this method in the `__init__` method of the `Coder` class. Here are the changes you need to make: ```python aider/coder.py <<<<<<< ORIGINAL class Coder: abs_fnames = None repo = None last_aider_commit_hash = None last_asked_for_commit_time = 0 def __init__( ======= class Coder: abs_fnames = None repo = None last_aider_commit_hash = None last_asked_for_commit_time = 0 def check_model_availability(self, main_model): available_models = openai.Model.list() model_ids = [model.id for model in available_models['data']] if main_model not in model_ids: raise ValueError(f"Model {main_model} is not available. Please choose from the available models: {model_ids}") def __init__( >>>>>>> UPDATED ``` ```python aider/coder.py <<<<<<< ORIGINAL self.main_model = main_model if main_model == "gpt-3.5-turbo": self.io.tool_error( f"aider doesn't work well with {main_model}, use gpt-4 for best results." ) self.set_repo(fnames) ======= self.check_model_availability(main_model) self.main_model = main_model if main_model == "gpt-3.5-turbo": self.io.tool_error( f"aider doesn't work well with {main_model}, use gpt-4 for best results." ) self.set_repo(fnames) >>>>>>> UPDATED ``` These changes will add a new method `check_model_availability` to the `Coder` class and call it in the `__init__` method to ensure the `main_model` is available in the list of OpenAI models. If not, it will raise a `ValueError` with an appropriate error message. --- aider/coder.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/aider/coder.py b/aider/coder.py index af761d62f..e7763dc07 100755 --- a/aider/coder.py +++ b/aider/coder.py @@ -29,6 +29,12 @@ class Coder: last_aider_commit_hash = None last_asked_for_commit_time = 0 + def check_model_availability(self, main_model): + available_models = openai.Model.list() + model_ids = [model.id for model in available_models['data']] + if main_model not in model_ids: + raise ValueError(f"Model {main_model} is not available. Please choose from the available models: {model_ids}") + def __init__( self, io, @@ -64,6 +70,7 @@ class Coder: self.console = Console(force_terminal=True, no_color=True) self.commands = Commands(self.io, self) + self.check_model_availability(main_model) self.main_model = main_model if main_model == "gpt-3.5-turbo": self.io.tool_error(