diff --git a/plugins/wasm-go/extensions/ai-proxy/provider/provider.go b/plugins/wasm-go/extensions/ai-proxy/provider/provider.go index 8081f6a6d0..478f7a24b6 100644 --- a/plugins/wasm-go/extensions/ai-proxy/provider/provider.go +++ b/plugins/wasm-go/extensions/ai-proxy/provider/provider.go @@ -188,6 +188,9 @@ type ProviderConfig struct { // @Title zh-CN 启用通义千问搜索服务 // @Description zh-CN 仅适用于通义千问服务,表示是否启用通义千问的互联网搜索功能。 qwenEnableSearch bool `required:"false" yaml:"qwenEnableSearch" json:"qwenEnableSearch"` + // @Title zh-CN 通义千问服务域名 + // @Description zh-CN 仅适用于通义千问服务,默认转发域名为 dashscope.aliyuncs.com, 当使用金融云服务时,可以设置为 dashscope-finance.aliyuncs.com + qwenDomain string `required:"false" yaml:"qwenDomain" json:"qwenDomain"` // @Title zh-CN 开启通义千问兼容模式 // @Description zh-CN 启用通义千问兼容模式后,将调用千问的兼容模式接口,同时对请求/响应不做修改。 qwenEnableCompatible bool `required:"false" yaml:"qwenEnableCompatible" json:"qwenEnableCompatible"` @@ -278,6 +281,10 @@ func (c *ProviderConfig) FromJson(json gjson.Result) { } c.qwenEnableSearch = json.Get("qwenEnableSearch").Bool() c.qwenEnableCompatible = json.Get("qwenEnableCompatible").Bool() + c.qwenDomain = json.Get("qwenDomain").String() + if c.qwenDomain != "" { + // TODO: validate the domain, if not valid, set to default + } c.ollamaServerHost = json.Get("ollamaServerHost").String() c.ollamaServerPort = uint32(json.Get("ollamaServerPort").Uint()) c.modelMapping = make(map[string]string) diff --git a/plugins/wasm-go/extensions/ai-proxy/provider/qwen.go b/plugins/wasm-go/extensions/ai-proxy/provider/qwen.go index 1f78b76cd5..a4a727724e 100644 --- a/plugins/wasm-go/extensions/ai-proxy/provider/qwen.go +++ b/plugins/wasm-go/extensions/ai-proxy/provider/qwen.go @@ -23,7 +23,7 @@ import ( const ( qwenResultFormatMessage = "message" - qwenDomain = "dashscope.aliyuncs.com" + qwenDefaultDomain = "dashscope.aliyuncs.com" qwenChatCompletionPath = "/api/v1/services/aigc/text-generation/generation" qwenTextEmbeddingPath = "/api/v1/services/embeddings/text-embedding/text-embedding" qwenCompatiblePath = "/compatible-mode/v1/chat/completions" @@ -64,7 +64,11 @@ type qwenProvider struct { } func (m *qwenProvider) TransformRequestHeaders(ctx wrapper.HttpContext, apiName ApiName, headers http.Header, log wrapper.Log) { - util.OverwriteRequestHostHeader(headers, qwenDomain) + if m.config.qwenDomain != "" { + util.OverwriteRequestHostHeader(headers, m.config.qwenDomain) + } else { + util.OverwriteRequestHostHeader(headers, qwenDefaultDomain) + } util.OverwriteRequestAuthorizationHeader(headers, "Bearer "+m.config.GetApiTokenInUse(ctx)) if m.config.qwenEnableCompatible {