Skip to content

Commit fd3ebc3

Browse files
committed
Improve handling of OpenAI API key 🗝️, especially for GitHub Actions
1 parent 65a2ca2 commit fd3ebc3

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

aicodebot/cli.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,9 @@ def write_config_file(config_data):
188188
console.print(f"✅ Created config file at {config_file}")
189189

190190
is_terminal = sys.stdout.isatty()
191+
openai_api_key = openai_api_key or config_data["openai_api_key"] or os.getenv("OPENAI_API_KEY")
191192
if not is_terminal:
192-
if config_data["openai_api_key"] is None:
193+
if openai_api_key is None:
193194
raise click.ClickException(
194195
"🛑 No OpenAI API key found.\n"
195196
"Please set the OPENAI_API_KEY environment variable or call configure with --openai-api-key set."
@@ -437,7 +438,7 @@ def setup_config():
437438
existing_config = read_config()
438439
if not existing_config:
439440
console.print("Welcome to AI Code Bot! 🤖. Let's set up your config file.\n", style=bot_style)
440-
configure.callback(openai_api_key=None, verbose=0)
441+
configure.callback(openai_api_key=os.getenv("OPENAI_API_KEY"), verbose=0)
441442
sys.exit()
442443
else:
443444
return existing_config

0 commit comments

Comments
 (0)