aider/aider
Paul Gauthier 3bef60ecf0 aider: Added option to set OpenAI API base endpoint.
# Context:
USER: is it possible to add OPEN_AI_BASE or openai.api_base endpoint

default:
openai.api_base = "https://api.openai.com/v1/chat/completions"

ASSISTANT: Yes, you can add an option to set the OpenAI API base endpoint. Here's how to do it:

1. Add a new argument to the argument parser in `aider/main.py`.
2. Set the `openai.api_base` in the `Coder` class in `aider/coder.py`.

Here are the changes you need to make:

```python
aider/main.py
<<<<<<< ORIGINAL
    parser.add_argument(
        "--openai-api-key",
        metavar="OPENAI_API_KEY",
        help="Specify the OpenAI API key",
        env_var="OPENAI_API_KEY",
    )
=======
    parser.add_argument(
        "--openai-api-key",
        metavar="OPENAI_API_KEY",
        help="Specify the OpenAI API key",
        env_var="OPENAI_API_KEY",
    )
    parser.add_argument(
        "--openai-api-base",
        metavar="OPENAI_API_BASE",
        default="https://api.openai.com/v1/chat/completions",
        help="Specify the OpenAI API base endpoint (default: https://api.openai.com/v1/chat/completions)",
    )
>>>>>>> UPDATED
```

```python
aider/coder.py
<<<<<<< ORIGINAL
        if openai_api_key:
            openai.api_key = openai_api_key
        else:
            raise MissingAPIKeyError("No OpenAI API key provided.")
=======
        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
>>>>>>> UPDATED
```

Now you can use the `--openai-api-base` option to set the OpenAI API base endpoint when running the script.
2023-06-10 06:40:15 -07:00
..
__init__.py initial 2023-05-09 11:00:32 -07:00
coder.py aider: Added option to set OpenAI API base endpoint. 2023-06-10 06:40:15 -07:00
commands.py Use models...max_context_tokens 2023-06-07 12:37:10 -07:00
diffs.py aider: Updated diff_partial_update function to include 5 lines of context in unified_diff function call. 2023-06-06 18:13:36 -07:00
dump.py isort 2023-05-28 22:47:38 -07:00
io.py Fix issue with quoting /commands 2023-06-05 11:49:27 -07:00
main.py aider: Added option to set OpenAI API base endpoint. 2023-06-10 06:40:15 -07:00
models.py added adier/models.py 2023-06-07 13:14:55 -07:00
prompts.py prompt 2023-06-05 22:19:51 -07:00
repomap.py Update debugging main in repomap 2023-06-07 14:57:57 -07:00
utils.py Ensure leading_whitespace is actually space 2023-06-10 06:16:22 -07:00