Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gelleson
Copy link

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.

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

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.
Copy link

codecov bot commented Mar 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.46%. Comparing base (0925563) to head (7990f40).

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.
📢 Have feedback on the report? Share it here.

@sashabaranov
Copy link
Owner

@gelleson thank you for the PR! And sorry for taking so long for reviewing it — I think it's an important very area and should be treated appropriately.

In the context of #700 — do we maybe make this change more general, so different providers would handle API keys and specific URL formatting?

@@ -23,10 +24,23 @@ const (

const AzureAPIKeyHeader = "api-key"

type AuthBuilder func(req *http.Request)
Copy link
Owner

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

@sashabaranov
Copy link
Owner

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants