mirror of
https://github.com/alibaba/higress.git
synced 2026-06-05 18:57:30 +08:00
fix: baidu api issue (#1685)
This commit is contained in:
@@ -22,7 +22,7 @@ type ai360Provider struct {
|
|||||||
contextCache *contextCache
|
contextCache *contextCache
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *ai360ProviderInitializer) ValidateConfig(config ProviderConfig) error {
|
func (m *ai360ProviderInitializer) ValidateConfig(config *ProviderConfig) error {
|
||||||
if config.apiTokens == nil || len(config.apiTokens) == 0 {
|
if config.apiTokens == nil || len(config.apiTokens) == 0 {
|
||||||
return errors.New("no apiToken found in provider config")
|
return errors.New("no apiToken found in provider config")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import (
|
|||||||
type azureProviderInitializer struct {
|
type azureProviderInitializer struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *azureProviderInitializer) ValidateConfig(config ProviderConfig) error {
|
func (m *azureProviderInitializer) ValidateConfig(config *ProviderConfig) error {
|
||||||
if config.azureServiceUrl == "" {
|
if config.azureServiceUrl == "" {
|
||||||
return errors.New("missing azureServiceUrl in provider config")
|
return errors.New("missing azureServiceUrl in provider config")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ const (
|
|||||||
type baichuanProviderInitializer struct {
|
type baichuanProviderInitializer struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *baichuanProviderInitializer) ValidateConfig(config ProviderConfig) error {
|
func (m *baichuanProviderInitializer) ValidateConfig(config *ProviderConfig) error {
|
||||||
if config.apiTokens == nil || len(config.apiTokens) == 0 {
|
if config.apiTokens == nil || len(config.apiTokens) == 0 {
|
||||||
return errors.New("no apiToken found in provider config")
|
return errors.New("no apiToken found in provider config")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,16 +34,15 @@ const (
|
|||||||
|
|
||||||
type baiduProviderInitializer struct{}
|
type baiduProviderInitializer struct{}
|
||||||
|
|
||||||
func (g *baiduProviderInitializer) ValidateConfig(config ProviderConfig) error {
|
func (g *baiduProviderInitializer) ValidateConfig(config *ProviderConfig) error {
|
||||||
if config.baiduAccessKeyAndSecret == nil || len(config.baiduAccessKeyAndSecret) == 0 {
|
if config.baiduAccessKeyAndSecret == nil || len(config.baiduAccessKeyAndSecret) == 0 {
|
||||||
return errors.New("no baiduAccessKeyAndSecret found in provider config")
|
return errors.New("no baiduAccessKeyAndSecret found in provider config")
|
||||||
}
|
}
|
||||||
if config.baiduApiTokenServiceName == "" {
|
if config.baiduApiTokenServiceName == "" {
|
||||||
return errors.New("no baiduApiTokenServiceName found in provider config")
|
return errors.New("no baiduApiTokenServiceName found in provider config")
|
||||||
}
|
}
|
||||||
if !config.failover.enabled {
|
// baidu use access key and access secret to refresh apiToken regularly, the apiToken should be accessed globally (via all Wasm VMs)
|
||||||
config.useGlobalApiToken = true
|
config.useGlobalApiToken = true
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ type claudeTextGenDelta struct {
|
|||||||
StopSequence *string `json:"stop_sequence"`
|
StopSequence *string `json:"stop_sequence"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *claudeProviderInitializer) ValidateConfig(config ProviderConfig) error {
|
func (c *claudeProviderInitializer) ValidateConfig(config *ProviderConfig) error {
|
||||||
if config.apiTokens == nil || len(config.apiTokens) == 0 {
|
if config.apiTokens == nil || len(config.apiTokens) == 0 {
|
||||||
return errors.New("no apiToken found in provider config")
|
return errors.New("no apiToken found in provider config")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ const (
|
|||||||
type cloudflareProviderInitializer struct {
|
type cloudflareProviderInitializer struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *cloudflareProviderInitializer) ValidateConfig(config ProviderConfig) error {
|
func (c *cloudflareProviderInitializer) ValidateConfig(config *ProviderConfig) error {
|
||||||
if config.apiTokens == nil || len(config.apiTokens) == 0 {
|
if config.apiTokens == nil || len(config.apiTokens) == 0 {
|
||||||
return errors.New("no apiToken found in provider config")
|
return errors.New("no apiToken found in provider config")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ const (
|
|||||||
|
|
||||||
type cohereProviderInitializer struct{}
|
type cohereProviderInitializer struct{}
|
||||||
|
|
||||||
func (m *cohereProviderInitializer) ValidateConfig(config ProviderConfig) error {
|
func (m *cohereProviderInitializer) ValidateConfig(config *ProviderConfig) error {
|
||||||
if config.apiTokens == nil || len(config.apiTokens) == 0 {
|
if config.apiTokens == nil || len(config.apiTokens) == 0 {
|
||||||
return errors.New("no apiToken found in provider config")
|
return errors.New("no apiToken found in provider config")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ const (
|
|||||||
|
|
||||||
type cozeProviderInitializer struct{}
|
type cozeProviderInitializer struct{}
|
||||||
|
|
||||||
func (m *cozeProviderInitializer) ValidateConfig(config ProviderConfig) error {
|
func (m *cozeProviderInitializer) ValidateConfig(config *ProviderConfig) error {
|
||||||
if config.apiTokens == nil || len(config.apiTokens) == 0 {
|
if config.apiTokens == nil || len(config.apiTokens) == 0 {
|
||||||
return errors.New("no apiToken found in provider config")
|
return errors.New("no apiToken found in provider config")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ type deeplResponseTranslation struct {
|
|||||||
Text string `json:"text"`
|
Text string `json:"text"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *deeplProviderInitializer) ValidateConfig(config ProviderConfig) error {
|
func (d *deeplProviderInitializer) ValidateConfig(config *ProviderConfig) error {
|
||||||
if config.targetLang == "" {
|
if config.targetLang == "" {
|
||||||
return errors.New("missing targetLang in deepl provider config")
|
return errors.New("missing targetLang in deepl provider config")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ const (
|
|||||||
type deepseekProviderInitializer struct {
|
type deepseekProviderInitializer struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *deepseekProviderInitializer) ValidateConfig(config ProviderConfig) error {
|
func (m *deepseekProviderInitializer) ValidateConfig(config *ProviderConfig) error {
|
||||||
if config.apiTokens == nil || len(config.apiTokens) == 0 {
|
if config.apiTokens == nil || len(config.apiTokens) == 0 {
|
||||||
return errors.New("no apiToken found in provider config")
|
return errors.New("no apiToken found in provider config")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ const (
|
|||||||
|
|
||||||
type doubaoProviderInitializer struct{}
|
type doubaoProviderInitializer struct{}
|
||||||
|
|
||||||
func (m *doubaoProviderInitializer) ValidateConfig(config ProviderConfig) error {
|
func (m *doubaoProviderInitializer) ValidateConfig(config *ProviderConfig) error {
|
||||||
if config.apiTokens == nil || len(config.apiTokens) == 0 {
|
if config.apiTokens == nil || len(config.apiTokens) == 0 {
|
||||||
return errors.New("no apiToken found in provider config")
|
return errors.New("no apiToken found in provider config")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/alibaba/higress/plugins/wasm-go/extensions/ai-proxy/util"
|
"github.com/alibaba/higress/plugins/wasm-go/extensions/ai-proxy/util"
|
||||||
"github.com/alibaba/higress/plugins/wasm-go/pkg/wrapper"
|
"github.com/alibaba/higress/plugins/wasm-go/pkg/wrapper"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
@@ -558,7 +558,8 @@ func (c *ProviderConfig) GetApiTokenInUse(ctx wrapper.HttpContext) string {
|
|||||||
func (c *ProviderConfig) SetApiTokenInUse(ctx wrapper.HttpContext, log wrapper.Log) {
|
func (c *ProviderConfig) SetApiTokenInUse(ctx wrapper.HttpContext, log wrapper.Log) {
|
||||||
var apiToken string
|
var apiToken string
|
||||||
if c.isFailoverEnabled() || c.useGlobalApiToken {
|
if c.isFailoverEnabled() || c.useGlobalApiToken {
|
||||||
// if enable apiToken failover, only use available apiToken
|
// if enable apiToken failover, only use available apiToken from global apiTokens list
|
||||||
|
// or the apiToken need to be accessed globally (via all Wasm VMs, e.g. baidu),
|
||||||
apiToken = c.GetGlobalRandomToken(log)
|
apiToken = c.GetGlobalRandomToken(log)
|
||||||
} else {
|
} else {
|
||||||
apiToken = c.GetRandomToken()
|
apiToken = c.GetRandomToken()
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ const (
|
|||||||
type geminiProviderInitializer struct {
|
type geminiProviderInitializer struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *geminiProviderInitializer) ValidateConfig(config ProviderConfig) error {
|
func (g *geminiProviderInitializer) ValidateConfig(config *ProviderConfig) error {
|
||||||
if config.apiTokens == nil || len(config.apiTokens) == 0 {
|
if config.apiTokens == nil || len(config.apiTokens) == 0 {
|
||||||
return errors.New("no apiToken found in provider config")
|
return errors.New("no apiToken found in provider config")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ type githubProvider struct {
|
|||||||
contextCache *contextCache
|
contextCache *contextCache
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *githubProviderInitializer) ValidateConfig(config ProviderConfig) error {
|
func (m *githubProviderInitializer) ValidateConfig(config *ProviderConfig) error {
|
||||||
if config.apiTokens == nil || len(config.apiTokens) == 0 {
|
if config.apiTokens == nil || len(config.apiTokens) == 0 {
|
||||||
return errors.New("no apiToken found in provider config")
|
return errors.New("no apiToken found in provider config")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ const (
|
|||||||
|
|
||||||
type groqProviderInitializer struct{}
|
type groqProviderInitializer struct{}
|
||||||
|
|
||||||
func (g *groqProviderInitializer) ValidateConfig(config ProviderConfig) error {
|
func (g *groqProviderInitializer) ValidateConfig(config *ProviderConfig) error {
|
||||||
if config.apiTokens == nil || len(config.apiTokens) == 0 {
|
if config.apiTokens == nil || len(config.apiTokens) == 0 {
|
||||||
return errors.New("no apiToken found in provider config")
|
return errors.New("no apiToken found in provider config")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ type hunyuanChatMessage struct {
|
|||||||
Content string `json:"Content,omitempty"`
|
Content string `json:"Content,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *hunyuanProviderInitializer) ValidateConfig(config ProviderConfig) error {
|
func (m *hunyuanProviderInitializer) ValidateConfig(config *ProviderConfig) error {
|
||||||
// 校验hunyuan id 和 key的合法性
|
// 校验hunyuan id 和 key的合法性
|
||||||
if len(config.hunyuanAuthId) != hunyuanAuthIdLen || len(config.hunyuanAuthKey) != hunyuanAuthKeyLen {
|
if len(config.hunyuanAuthId) != hunyuanAuthIdLen || len(config.hunyuanAuthKey) != hunyuanAuthKeyLen {
|
||||||
return errors.New("hunyuanAuthId / hunyuanAuthKey is illegal in config file")
|
return errors.New("hunyuanAuthId / hunyuanAuthKey is illegal in config file")
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ const (
|
|||||||
type minimaxProviderInitializer struct {
|
type minimaxProviderInitializer struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *minimaxProviderInitializer) ValidateConfig(config ProviderConfig) error {
|
func (m *minimaxProviderInitializer) ValidateConfig(config *ProviderConfig) error {
|
||||||
// If using the chat completion Pro API, a group ID must be set.
|
// If using the chat completion Pro API, a group ID must be set.
|
||||||
if minimaxApiTypePro == config.minimaxApiType && config.minimaxGroupId == "" {
|
if minimaxApiTypePro == config.minimaxApiType && config.minimaxGroupId == "" {
|
||||||
return errors.New(fmt.Sprintf("missing minimaxGroupId in provider config when minimaxApiType is %s", minimaxApiTypePro))
|
return errors.New(fmt.Sprintf("missing minimaxGroupId in provider config when minimaxApiType is %s", minimaxApiTypePro))
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ const (
|
|||||||
|
|
||||||
type mistralProviderInitializer struct{}
|
type mistralProviderInitializer struct{}
|
||||||
|
|
||||||
func (m *mistralProviderInitializer) ValidateConfig(config ProviderConfig) error {
|
func (m *mistralProviderInitializer) ValidateConfig(config *ProviderConfig) error {
|
||||||
if config.apiTokens == nil || len(config.apiTokens) == 0 {
|
if config.apiTokens == nil || len(config.apiTokens) == 0 {
|
||||||
return errors.New("no apiToken found in provider config")
|
return errors.New("no apiToken found in provider config")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ const (
|
|||||||
type moonshotProviderInitializer struct {
|
type moonshotProviderInitializer struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *moonshotProviderInitializer) ValidateConfig(config ProviderConfig) error {
|
func (m *moonshotProviderInitializer) ValidateConfig(config *ProviderConfig) error {
|
||||||
if config.moonshotFileId != "" && config.context != nil {
|
if config.moonshotFileId != "" && config.context != nil {
|
||||||
return errors.New("moonshotFileId and context cannot be configured at the same time")
|
return errors.New("moonshotFileId and context cannot be configured at the same time")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ const (
|
|||||||
type ollamaProviderInitializer struct {
|
type ollamaProviderInitializer struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *ollamaProviderInitializer) ValidateConfig(config ProviderConfig) error {
|
func (m *ollamaProviderInitializer) ValidateConfig(config *ProviderConfig) error {
|
||||||
if config.ollamaServerHost == "" {
|
if config.ollamaServerHost == "" {
|
||||||
return errors.New("missing ollamaServerHost in provider config")
|
return errors.New("missing ollamaServerHost in provider config")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ const (
|
|||||||
type openaiProviderInitializer struct {
|
type openaiProviderInitializer struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *openaiProviderInitializer) ValidateConfig(config ProviderConfig) error {
|
func (m *openaiProviderInitializer) ValidateConfig(config *ProviderConfig) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type providerInitializer interface {
|
type providerInitializer interface {
|
||||||
ValidateConfig(ProviderConfig) error
|
ValidateConfig(*ProviderConfig) error
|
||||||
CreateProvider(ProviderConfig) (Provider, error)
|
CreateProvider(ProviderConfig) (Provider, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -405,7 +405,7 @@ func (c *ProviderConfig) Validate() error {
|
|||||||
if !has {
|
if !has {
|
||||||
return errors.New("unknown provider type: " + c.typ)
|
return errors.New("unknown provider type: " + c.typ)
|
||||||
}
|
}
|
||||||
if err := initializer.ValidateConfig(*c); err != nil {
|
if err := initializer.ValidateConfig(c); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ const (
|
|||||||
type qwenProviderInitializer struct {
|
type qwenProviderInitializer struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *qwenProviderInitializer) ValidateConfig(config ProviderConfig) error {
|
func (m *qwenProviderInitializer) ValidateConfig(config *ProviderConfig) error {
|
||||||
if len(config.qwenFileIds) != 0 && config.context != nil {
|
if len(config.qwenFileIds) != 0 && config.context != nil {
|
||||||
return errors.New("qwenFileIds and context cannot be configured at the same time")
|
return errors.New("qwenFileIds and context cannot be configured at the same time")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ type sparkStreamResponse struct {
|
|||||||
Created int64 `json:"created"`
|
Created int64 `json:"created"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *sparkProviderInitializer) ValidateConfig(config ProviderConfig) error {
|
func (i *sparkProviderInitializer) ValidateConfig(config *ProviderConfig) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ const (
|
|||||||
type stepfunProviderInitializer struct {
|
type stepfunProviderInitializer struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *stepfunProviderInitializer) ValidateConfig(config ProviderConfig) error {
|
func (m *stepfunProviderInitializer) ValidateConfig(config *ProviderConfig) error {
|
||||||
if config.apiTokens == nil || len(config.apiTokens) == 0 {
|
if config.apiTokens == nil || len(config.apiTokens) == 0 {
|
||||||
return errors.New("no apiToken found in provider config")
|
return errors.New("no apiToken found in provider config")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ const (
|
|||||||
|
|
||||||
type togetherAIProviderInitializer struct{}
|
type togetherAIProviderInitializer struct{}
|
||||||
|
|
||||||
func (m *togetherAIProviderInitializer) ValidateConfig(config ProviderConfig) error {
|
func (m *togetherAIProviderInitializer) ValidateConfig(config *ProviderConfig) error {
|
||||||
if config.apiTokens == nil || len(config.apiTokens) == 0 {
|
if config.apiTokens == nil || len(config.apiTokens) == 0 {
|
||||||
return errors.New("no apiToken found in provider config")
|
return errors.New("no apiToken found in provider config")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ const (
|
|||||||
type yiProviderInitializer struct {
|
type yiProviderInitializer struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *yiProviderInitializer) ValidateConfig(config ProviderConfig) error {
|
func (m *yiProviderInitializer) ValidateConfig(config *ProviderConfig) error {
|
||||||
if config.apiTokens == nil || len(config.apiTokens) == 0 {
|
if config.apiTokens == nil || len(config.apiTokens) == 0 {
|
||||||
return errors.New("no apiToken found in provider config")
|
return errors.New("no apiToken found in provider config")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ const (
|
|||||||
|
|
||||||
type zhipuAiProviderInitializer struct{}
|
type zhipuAiProviderInitializer struct{}
|
||||||
|
|
||||||
func (m *zhipuAiProviderInitializer) ValidateConfig(config ProviderConfig) error {
|
func (m *zhipuAiProviderInitializer) ValidateConfig(config *ProviderConfig) error {
|
||||||
if config.apiTokens == nil || len(config.apiTokens) == 0 {
|
if config.apiTokens == nil || len(config.apiTokens) == 0 {
|
||||||
return errors.New("no apiToken found in provider config")
|
return errors.New("no apiToken found in provider config")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user