mirror of
https://github.com/alibaba/higress.git
synced 2026-06-08 12:17:28 +08:00
Ai proxy support coze (#1387)
This commit is contained in:
44
plugins/wasm-go/extensions/ai-proxy/provider/coze.go
Normal file
44
plugins/wasm-go/extensions/ai-proxy/provider/coze.go
Normal 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
|
||||
}
|
||||
@@ -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{},
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user