-
-
Notifications
You must be signed in to change notification settings - Fork 802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Created --reset-key flag to update OpenAI key #395
Conversation
@TheR1D Any suggested changes to get this in? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this option doesn't align with prioritized environment variables in config now, since we can't reset user exported OPENAI_API_KEY
. But we could add better error handling into client._request
simply checking respone status code for 403/401
printing the error text and raising Exit
with error raise typer.Exit(code=1)
.
I've moved the error handling to client._request as suggested. As for the reset functionality I added a note to the "help" section of the command as a reminder that the environment variable will still be prioritized. I still believe having a --reset-key option is worthwhile as I would've liked to use it myself when first trying the tool. Instead of having to navigate to the .sgptrc file and update it manually it would've been nice to have this command. The config.get() function properly prioritizes the use of the env key if it exists so updating the .sgptrc file wouldn't change this behavior. In the case that a user runs this command while already having the env variable, I highlight in yellow that their env key will still be used. User updates key with env variable defined: No env variable defined, and fake key: Let me know what you think @TheR1D . Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is very common in CLI applications to use runtime configuration file or ENV variables to set API keys (without having dedicated CLI options to reset some of config values). Please remove reset key option, if we show user proper message, it is clear how to reset it.
Adjusted to reflect @TheR1D 's comments. When using an invalid key the output now looks like: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @Ismail-Ben
Please check lint issues. |
Thank you, merged. |
Resolves: #30
Added --reset-key flag to update OPENAI_API_KEY in .sgptrc file. Also verified with a dummy chat completion that the newly inputted key works.
Sample output with 2 non-valid keys followed by a real key: