aider: Added support for passing openai_api_base into the Coder class.

# Context:
USER: we need to pass `openai_api_base` into Coder
ASSISTANT: To pass `openai_api_base` into the Coder class, you need to modify the `aider/main.py` file and update the Coder class instantiation. Here's the change you need to make:

```python
aider/main.py
<<<<<<< ORIGINAL
    coder = Coder(
        io,
        main_model=args.model,
        fnames=args.files,
        pretty=args.pretty,
        show_diffs=args.show_diffs,
        auto_commits=args.auto_commits,
        dirty_commits=args.dirty_commits,
        dry_run=args.dry_run,
        map_tokens=args.map_tokens,
        verbose=args.verbose,
        openai_api_key=args.openai_api_key,
    )
=======
    coder = Coder(
        io,
        main_model=args.model,
        fnames=args.files,
        pretty=args.pretty,
        show_diffs=args.show_diffs,
        auto_commits=args.auto_commits,
        dirty_commits=args.dirty_commits,
        dry_run=args.dry_run,
        map_tokens=args.map_tokens,
        verbose=args.verbose,
        openai_api_key=args.openai_api_key,
        openai_api_base=args.openai_api_base,
    )
>>>>>>> UPDATED
```

Now, you also need to update the `__init__` method of the Coder class in the `aider/coder.py` file to accept the `openai_api_base` argument and use it:

```python
aider/coder.py
<<<<<<< ORIGINAL
    def __init__(
        self,
        io,
        main_model=models.GPT4.name,
        fnames=None,
        pretty=True,
        show_diffs=False,
        auto_commits=True,
        dirty_commits=True,
        dry_run=False,
        map_tokens=1024,
        verbose=False,
        openai_api_key=None,
    ):
        if not openai_api_key:
            raise MissingAPIKeyError("No OpenAI API key provided.")
        openai.api_key = openai_api_key
        openai.api_base = args.openai_api_base
=======
    def __init__(
        self,
        io,
        main_model=models.GPT4.name,
        fnames=None,
        pretty=True,
        show_diffs=False,
        auto_commits=True,
        dirty_commits=True,
        dry_run=False,
        map_tokens=1024,
        verbose=False,
        openai_api_key=None,
        openai_api_base=None,
    ):
        if not openai_api_key:
            raise MissingAPIKeyError("No OpenAI API key provided.")
        openai.api_key = openai_api_key
        openai.api_base = openai_api_base
>>>>>>> UPDATED
```

These changes will allow you to pass the `openai_api_base` value into the Coder class and use it.
This commit is contained in:
Paul Gauthier 2023-06-10 10:40:54 -07:00
parent 3bef60ecf0
commit 3e7f791112
2 changed files with 3 additions and 1 deletions

View file

@ -50,11 +50,12 @@ class Coder:
map_tokens=1024,
verbose=False,
openai_api_key=None,
openai_api_base=None,
):
if not openai_api_key:
raise MissingAPIKeyError("No OpenAI API key provided.")
openai.api_key = openai_api_key
openai.api_base = args.openai_api_base
openai.api_base = openai_api_base
self.verbose = verbose
self.abs_fnames = set()

View file

@ -227,6 +227,7 @@ def main(args=None, input=None, output=None):
map_tokens=args.map_tokens,
verbose=args.verbose,
openai_api_key=args.openai_api_key,
openai_api_base=args.openai_api_base,
)
if args.dirty_commits: