-
-
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
openai.DefaultAzureConfig support configure apiVersion #414
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ const ( | |
|
||
azureAPIPrefix = "openai" | ||
azureDeploymentsPrefix = "deployments" | ||
azureDefaultAPIVersion = "2023-05-15" | ||
) | ||
|
||
type APIType string | ||
|
@@ -50,13 +51,21 @@ func DefaultConfig(authToken string) ClientConfig { | |
} | ||
} | ||
|
||
func DefaultAzureConfig(apiKey, baseURL string) ClientConfig { | ||
return ClientConfig{ | ||
type AzureConfigOption func(*ClientConfig) | ||
|
||
func WithAzureAPIVersion(apiVersion string) AzureConfigOption { | ||
return func(c *ClientConfig) { | ||
c.APIVersion = apiVersion | ||
} | ||
} | ||
|
||
func DefaultAzureConfig(apiKey, baseURL string, opts ...AzureConfigOption) ClientConfig { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @fregie The functional options approach you're proposing is really slick! You might already know this, but you can also change the cfg := openai.DefaultAzureConfig("apiKey", "baseURL")
cfg.APIVersion = "APIVersion" The responsibility of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest to add the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@fregie I see, I understand. So, the APIVersion is not optional but required. In that case, I thought the following signature would be appropriate.
@sashabaranov There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Folks, I just wanted to add my two cents here:
config := openai.DefaultConfig("auth token")
config.BaseURL = "my URL"
config.OrgID = "my org id"
config.EmptyMessagesLimit = 10000 and config := openai.DefaultConfig("auth token",
openai.WithBaseURL("my URL"),
openai.WithOrgID("my org id"),
openai.WithEmptyMessagesLimit(10000),
) My take is that we probably don't need
|
||
c := ClientConfig{ | ||
authToken: apiKey, | ||
BaseURL: baseURL, | ||
OrgID: "", | ||
APIType: APITypeAzure, | ||
APIVersion: "2023-05-15", | ||
APIVersion: azureDefaultAPIVersion, | ||
AzureModelMapperFunc: func(model string) string { | ||
return regexp.MustCompile(`[.:]`).ReplaceAllString(model, "") | ||
}, | ||
|
@@ -65,6 +74,10 @@ func DefaultAzureConfig(apiKey, baseURL string) ClientConfig { | |
|
||
EmptyMessagesLimit: defaultEmptyMessagesLimit, | ||
} | ||
for _, opt := range opts { | ||
opt(&c) | ||
} | ||
return c | ||
} | ||
|
||
func (ClientConfig) String() string { | ||
|
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.
@fregie That's a kind comment. 👍