-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Refactor authentication process and update tests accordingly #693
base: master
Are you sure you want to change the base?
Conversation
Updated the authentication process in the `ClientConfig` by replacing the `authToken` string with `AuthBuilder` functions. This allows setting up various authentication headers, supporting different types of authentication like OpenAI or Azure AD. As part of this update, corresponding tests have also been modified to work with the new authentication process.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #693 +/- ##
=======================================
Coverage 98.46% 98.46%
=======================================
Files 24 24
Lines 1366 1370 +4
=======================================
+ Hits 1345 1349 +4
Misses 15 15
Partials 6 6 ☔ View full report in Codecov by Sentry. |
@@ -23,10 +24,23 @@ const ( | |||
|
|||
const AzureAPIKeyHeader = "api-key" | |||
|
|||
type AuthBuilder func(req *http.Request) |
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 suggest we make it an interface with setAuthTokenForRequest
func
Considering #700, here's a sketch of how we can approach different API providers: type apiProvider interface { // not exposing the provider type itself?
SetAuthForRequest(req *http.Request)
GetFullURL(suffix string, args ...any) // Shouldn't be `any`, but a type-safe list like requestOption
}
type APIProviderConfig interface {
// whatever we need here
} client usage: config := openai.DefaultConfigWithAPIProvider(
openai.AzureOpenAIProviderConfig("your Azure OpenAI Key", "https://your Azure OpenAI Endpoint"),
)
client := openai.NewClientWithConfig(config) |
Updated the authentication process in the
ClientConfig
by replacing theauthToken
string withAuthBuilder
functions. This allows setting up various authentication headers, supporting different types of authentication like OpenAI or Azure AD. As part of this update, corresponding tests have also been modified to work with the new authentication process.A similar PR may already be submitted!
Please search among the Pull request before creating one.
If your changes introduce breaking changes, please prefix the title of your pull request with "[BREAKING_CHANGES]". This allows for clear identification of such changes in the 'What's Changed' section on the release page, making it developer-friendly.
Thanks for submitting a pull request! Please provide enough information so that others can review your pull request.
Describe the change
Please provide a clear and concise description of the changes you're proposing. Explain what problem it solves or what feature it adds.
Provide OpenAI documentation link
Provide a relevant API doc from https://platform.openai.com/docs/api-reference
Describe your solution
Describe how your changes address the problem or how they add the feature. This should include a brief description of your approach and any new libraries or dependencies you're using.
Tests
Briefly describe how you have tested these changes. If possible — please add integration tests.
Additional context
Add any other context or screenshots or logs about your pull request here. If the pull request relates to an open issue, please link to it.
Issue: #XXXX