mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-02 02:34:59 +00:00
aider: Added --openai-api-key
argument to the command-line parser, passed it to the Coder
class, and set the openai.api_key
accordingly.
# Context: USER: add a new arg --openai-api-key. pass it to Coder ASSISTANT: I will add a new argument `--openai-api-key` and pass it to the `Coder` class. Here are the changes: ```python aider/main.py <<<<<<< ORIGINAL parser.add_argument( "--no-dirty-commits", action="store_false", dest="dirty_commits", help="Disable dirty commit of changes", ) ======= parser.add_argument( "--no-dirty-commits", action="store_false", dest="dirty_commits", help="Disable dirty commit of changes", ) parser.add_argument( "--openai-api-key", metavar="OPENAI_API_KEY", help="Specify the OpenAI API key", ) >>>>>>> UPDATED ``` ```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, use_ctags=args.ctags, verbose=args.verbose, ) ======= 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, use_ctags=args.ctags, verbose=args.verbose, openai_api_key=args.openai_api_key, ) >>>>>>> UPDATED ``` ```python aider/coder.py <<<<<<< ORIGINAL openai.api_key = os.getenv("OPENAI_API_KEY") class Coder: abs_fnames = None repo = None last_aider_commit_hash = None last_asked_for_commit_time = 0 def __init__( self, io, main_model="gpt-4", fnames=None, pretty=True, show_diffs=False, auto_commits=True, dirty_commits=True, dry_run=False, use_ctags=False, verbose=False, ): ======= class Coder: abs_fnames = None repo = None last_aider_commit_hash = None last_asked_for_commit_time = 0 def __init__( self, io, main_model="gpt-4", fnames=None, pretty=True, show_diffs=False, auto_commits=True, dirty_commits=True, dry_run=False, use_ctags=False, verbose=False, openai_api_key=None, ): if openai_api_key: openai.api_key = openai_api_key else: openai.api_key = os.getenv("OPENAI_API_KEY") >>>>>>> UPDATED ``` These changes add the `--openai-api-key` argument to the command-line parser, pass it to the `Coder` class, and set the `openai.api_key` accordingly.
This commit is contained in:
parent
139a141be9
commit
abf73d00a2
2 changed files with 11 additions and 3 deletions
|
@ -127,6 +127,11 @@ def main(args=None, input=None, output=None):
|
|||
dest="dirty_commits",
|
||||
help="Disable dirty commit of changes",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--openai-api-key",
|
||||
metavar="OPENAI_API_KEY",
|
||||
help="Specify the OpenAI API key",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--dry-run",
|
||||
action="store_true",
|
||||
|
@ -194,6 +199,7 @@ def main(args=None, input=None, output=None):
|
|||
dry_run=args.dry_run,
|
||||
use_ctags=args.ctags,
|
||||
verbose=args.verbose,
|
||||
openai_api_key=args.openai_api_key,
|
||||
)
|
||||
if args.dirty_commits:
|
||||
coder.commit(ask=True, prefix="wip: ", which="repo_files")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue