change azure engine config to modelMapper (#306)
* change azure engine config to azure modelMapper config * Update go.mod * Revert "Update go.mod" This reverts commit 78d14c58f2a9ce668da43f6adbe20b60afcfe0d7. * lint fix * add test * lint fix * lint fix * lint fix * opt * opt * opt * opt
This commit is contained in:
28
config.go
28
config.go
@@ -2,6 +2,7 @@ package openai
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -26,13 +27,12 @@ const AzureAPIKeyHeader = "api-key"
|
||||
type ClientConfig struct {
|
||||
authToken string
|
||||
|
||||
BaseURL string
|
||||
OrgID string
|
||||
APIType APIType
|
||||
APIVersion string // required when APIType is APITypeAzure or APITypeAzureAD
|
||||
Engine string // required when APIType is APITypeAzure or APITypeAzureAD
|
||||
|
||||
HTTPClient *http.Client
|
||||
BaseURL string
|
||||
OrgID string
|
||||
APIType APIType
|
||||
APIVersion string // required when APIType is APITypeAzure or APITypeAzureAD
|
||||
AzureModelMapperFunc func(model string) string // replace model to azure deployment name func
|
||||
HTTPClient *http.Client
|
||||
|
||||
EmptyMessagesLimit uint
|
||||
}
|
||||
@@ -50,14 +50,16 @@ func DefaultConfig(authToken string) ClientConfig {
|
||||
}
|
||||
}
|
||||
|
||||
func DefaultAzureConfig(apiKey, baseURL, engine string) ClientConfig {
|
||||
func DefaultAzureConfig(apiKey, baseURL string) ClientConfig {
|
||||
return ClientConfig{
|
||||
authToken: apiKey,
|
||||
BaseURL: baseURL,
|
||||
OrgID: "",
|
||||
APIType: APITypeAzure,
|
||||
APIVersion: "2023-03-15-preview",
|
||||
Engine: engine,
|
||||
AzureModelMapperFunc: func(model string) string {
|
||||
return regexp.MustCompile(`[.:]`).ReplaceAllString(model, "")
|
||||
},
|
||||
|
||||
HTTPClient: &http.Client{},
|
||||
|
||||
@@ -68,3 +70,11 @@ func DefaultAzureConfig(apiKey, baseURL, engine string) ClientConfig {
|
||||
func (ClientConfig) String() string {
|
||||
return "<OpenAI API ClientConfig>"
|
||||
}
|
||||
|
||||
func (c ClientConfig) GetAzureDeploymentByModel(model string) string {
|
||||
if c.AzureModelMapperFunc != nil {
|
||||
return c.AzureModelMapperFunc(model)
|
||||
}
|
||||
|
||||
return model
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user