Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion relay/channel/zhipu_4v/adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
22 changes: 22 additions & 0 deletions relay/channel/zhipu_4v/relay-zhipu_v4.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}