diff --git a/relay/channel/zhipu_4v/adaptor.go b/relay/channel/zhipu_4v/adaptor.go index 0af8a16bbee..bb40705f23a 100644 --- a/relay/channel/zhipu_4v/adaptor.go +++ b/relay/channel/zhipu_4v/adaptor.go @@ -90,7 +90,7 @@ func (a *Adaptor) ConvertOpenAIRequest(c *gin.Context, info *relaycommon.RelayIn if lo.FromPtrOr(request.TopP, 0) >= 1 { request.TopP = lo.ToPtr(0.99) } - return requestOpenAI2Zhipu(*request), nil + return injectZhipuWebSearch(requestOpenAI2Zhipu(*request), request.WebSearchOptions), nil } func (a *Adaptor) ConvertRerankRequest(c *gin.Context, relayMode int, request dto.RerankRequest) (any, error) { diff --git a/relay/channel/zhipu_4v/relay-zhipu_v4.go b/relay/channel/zhipu_4v/relay-zhipu_v4.go index 91ef0c4764a..512488e3eb7 100644 --- a/relay/channel/zhipu_4v/relay-zhipu_v4.go +++ b/relay/channel/zhipu_4v/relay-zhipu_v4.go @@ -58,3 +58,25 @@ func requestOpenAI2Zhipu(request dto.GeneralOpenAIRequest) *dto.GeneralOpenAIReq } return out } + +func injectZhipuWebSearch(req *dto.GeneralOpenAIRequest, opts *dto.WebSearchOptions) any { + if opts == nil { + return req + } + ws := map[string]any{ + "enable": true, + "search_engine": "search_pro_jina", + } + // medium 不显式设值,使用智谱上游默认。 + switch opts.SearchContextSize { + case "low": + ws["count"] = 5 + case "high": + ws["count"] = 15 + ws["content_size"] = "high" + } + m := req.ToMap() + tools, _ := m["tools"].([]any) + m["tools"] = append(tools, map[string]any{"type": "web_search", "web_search": ws}) + return m +}