mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-30 01:04:59 +00:00
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.
This commit is contained in:
parent
806805c0b1
commit
3bef60ecf0
2 changed files with 9 additions and 3 deletions
|
@ -51,10 +51,10 @@ class Coder:
|
||||||
verbose=False,
|
verbose=False,
|
||||||
openai_api_key=None,
|
openai_api_key=None,
|
||||||
):
|
):
|
||||||
if openai_api_key:
|
if not openai_api_key:
|
||||||
openai.api_key = openai_api_key
|
|
||||||
else:
|
|
||||||
raise MissingAPIKeyError("No OpenAI API key provided.")
|
raise MissingAPIKeyError("No OpenAI API key provided.")
|
||||||
|
openai.api_key = openai_api_key
|
||||||
|
openai.api_base = args.openai_api_base
|
||||||
|
|
||||||
self.verbose = verbose
|
self.verbose = verbose
|
||||||
self.abs_fnames = set()
|
self.abs_fnames = set()
|
||||||
|
|
|
@ -151,6 +151,12 @@ def main(args=None, input=None, output=None):
|
||||||
help="Specify the OpenAI API key",
|
help="Specify the OpenAI API key",
|
||||||
env_var="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)",
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--dry-run",
|
"--dry-run",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue