-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Validate the OpenAI API key format #1635
Conversation
@microsoft-github-policy-service agree |
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.
To help with debugging when a config_list
is provided, we can add some info in the error message about the index of the config in the list which causes this error, by catching the error at line 359 of client.py.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1635 +/- ##
===========================================
+ Coverage 37.80% 57.42% +19.61%
===========================================
Files 50 50
Lines 5726 5733 +7
Branches 1296 1406 +110
===========================================
+ Hits 2165 3292 +1127
+ Misses 3390 2179 -1211
- Partials 171 262 +91
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
@sonichi: Thank you for guidance! I will make two updates to the current set of changes:
Updates en route. |
Increase the amount of internal validation for OpenAI API keys. The intent is to shorten the debugging loop in case of typos. The changes do *not* add validation for Azure OpenAI API keys. * Add the validation in `__init__` of `OpenAIClient`. We'll log a warning when the OpenAI API key isn't valid. * Introduce the `MOCK_OPEN_AI_API_KEY` constant for testing. * Add unit test coverage for the `is_valid_api_key` function.
822bc78
to
e271542
Compare
* Validate the OpenAI API key format Increase the amount of internal validation for OpenAI API keys. The intent is to shorten the debugging loop in case of typos. The changes do *not* add validation for Azure OpenAI API keys. * Add the validation in `__init__` of `OpenAIClient`. * Introduce the `MOCK_OPEN_AI_API_KEY` constant for testing. * Add unit test coverage for the `is_valid_api_key` function. * Validate the OpenAI API key format Increase the amount of internal validation for OpenAI API keys. The intent is to shorten the debugging loop in case of typos. The changes do *not* add validation for Azure OpenAI API keys. * Add the validation in `__init__` of `OpenAIClient`. * Introduce the `MOCK_OPEN_AI_API_KEY` constant for testing. *Add unit test coverage for the `is_valid_api_key` function. * Log a warning when register a default client fails. * Validate the OpenAI API key format Increase the amount of internal validation for OpenAI API keys. The intent is to shorten the debugging loop in case of typos. The changes do *not* add validation for Azure OpenAI API keys. * Add the validation in `__init__` of `OpenAIClient`. We'll log a warning when the OpenAI API key isn't valid. * Introduce the `MOCK_OPEN_AI_API_KEY` constant for testing. * Add unit test coverage for the `is_valid_api_key` function. * Check for OpenAI base_url before API key validation --------- Co-authored-by: Chi Wang <[email protected]>
Increase the amount of internal validation for OpenAI API keys. The intent is to shorten the debugging loop in case of invalid keys and typos. The changes do not add validation for Azure OpenAI API keys.
Add the validation in
__init__
ofOpenAIClient
.Introduce the
MOCK_OPEN_AI_API_KEY
constant for testing.Add unit test coverage for the
is_valid_api_key
function.Why are these changes needed?
The intent is to shorten the debugging loop in case of invalid keys and typos. In addition, we increase the correctness guarantees for
OpenAIClient
, i.e., theOpenAIClient
instance will be created only with the API key in a valid format.If anyone has a definition of constraints for Azure OpenAI API keys, then that will be a next step to increase the validation.
Topics for discussion:
logger.warning
be more appropriate thanraise ValueError(...)
?self._oai_client.api_key
by design to avoid leaking API keys. Is this overly paranoid?Related issue number
Checks