Ai proxy support coze (#1387)

This commit is contained in:
rinfx
2024-10-14 12:45:53 +08:00
committed by GitHub
parent 1a53c7b4d3
commit 952c9ec5dc
4 changed files with 68 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
package provider
import (
"errors"
"github.com/alibaba/higress/plugins/wasm-go/extensions/ai-proxy/util"
"github.com/alibaba/higress/plugins/wasm-go/pkg/wrapper"
"github.com/higress-group/proxy-wasm-go-sdk/proxywasm/types"
)
const (
cozeDomain = "api.coze.cn"
)
type cozeProviderInitializer struct{}
func (m *cozeProviderInitializer) ValidateConfig(config ProviderConfig) error {
if config.apiTokens == nil || len(config.apiTokens) == 0 {
return errors.New("no apiToken found in provider config")
}
return nil
}
func (m *cozeProviderInitializer) CreateProvider(config ProviderConfig) (Provider, error) {
return &cozeProvider{
config: config,
contextCache: createContextCache(&config),
}, nil
}
type cozeProvider struct {
config ProviderConfig
contextCache *contextCache
}
func (m *cozeProvider) GetProviderType() string {
return providerTypeCoze
}
func (m *cozeProvider) OnRequestHeaders(ctx wrapper.HttpContext, apiName ApiName, log wrapper.Log) (types.Action, error) {
_ = util.OverwriteRequestHost(cozeDomain)
_ = util.OverwriteRequestAuthorization("Bearer " + m.config.GetRandomToken())
return types.ActionContinue, nil
}

View File

@@ -42,6 +42,7 @@ const (
providerTypeMistral = "mistral"
providerTypeCohere = "cohere"
providerTypeDoubao = "doubao"
providerTypeCoze = "coze"
protocolOpenAI = "openai"
protocolOriginal = "original"
@@ -101,6 +102,7 @@ var (
providerTypeMistral: &mistralProviderInitializer{},
providerTypeCohere: &cohereProviderInitializer{},
providerTypeDoubao: &doubaoProviderInitializer{},
providerTypeCoze: &cozeProviderInitializer{},
}
)