From 22a0ed0ee241319b57d57af20ea0bf0a2a0a7e42 Mon Sep 17 00:00:00 2001 From: RedwindA Date: Sat, 12 Jul 2025 02:22:40 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=20xAI=20?= =?UTF-8?q?=E7=BD=91=E7=BB=9C=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dto/openai_request.go | 1 + relay/channel/xai/adaptor.go | 9 +++++++++ relay/channel/xai/constants.go | 2 ++ 3 files changed, 12 insertions(+) diff --git a/dto/openai_request.go b/dto/openai_request.go index a6567542..aa4f1962 100644 --- a/dto/openai_request.go +++ b/dto/openai_request.go @@ -55,6 +55,7 @@ type GeneralOpenAIRequest struct { EnableThinking any `json:"enable_thinking,omitempty"` // ali THINKING json.RawMessage `json:"thinking,omitempty"` // doubao ExtraBody json.RawMessage `json:"extra_body,omitempty"` + SearchParameters any `json:"search_parameters,omitempty"` //xai WebSearchOptions *WebSearchOptions `json:"web_search_options,omitempty"` // OpenRouter Params Usage json.RawMessage `json:"usage,omitempty"` diff --git a/relay/channel/xai/adaptor.go b/relay/channel/xai/adaptor.go index b5896415..17747dd5 100644 --- a/relay/channel/xai/adaptor.go +++ b/relay/channel/xai/adaptor.go @@ -56,6 +56,15 @@ func (a *Adaptor) ConvertOpenAIRequest(c *gin.Context, info *relaycommon.RelayIn if request == nil { return nil, errors.New("request is nil") } + if strings.HasSuffix(info.UpstreamModelName, "-search") { + info.UpstreamModelName = strings.TrimSuffix(info.UpstreamModelName, "-search") + request.Model = info.UpstreamModelName + toMap := request.ToMap() + toMap["search_parameters"] = map[string]any{ + "mode": "on", + } + return toMap, nil + } if strings.HasPrefix(request.Model, "grok-3-mini") { if request.MaxCompletionTokens == 0 && request.MaxTokens != 0 { request.MaxCompletionTokens = request.MaxTokens diff --git a/relay/channel/xai/constants.go b/relay/channel/xai/constants.go index 685fe3bb..311b4bb6 100644 --- a/relay/channel/xai/constants.go +++ b/relay/channel/xai/constants.go @@ -1,6 +1,8 @@ package xai var ModelList = []string{ + // grok-4 + "grok-4", "grok-4-0709", "grok-4-0709-search", // grok-3 "grok-3-beta", "grok-3-mini-beta", // grok-3 mini From b7f24b428b49b7c15ae197ce2e670514d734892f Mon Sep 17 00:00:00 2001 From: RedwindA Date: Sat, 12 Jul 2025 02:23:10 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E8=B0=83=E6=95=B4=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=E9=A1=BA=E5=BA=8F=E4=BB=A5=E9=81=BF=E5=85=8D=E5=86=99?= =?UTF-8?q?=E5=85=A5=E6=97=A5=E5=BF=97=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 996b65b3..ca3da601 100644 --- a/main.go +++ b/main.go @@ -168,11 +168,11 @@ func InitResources() error { common.SysLog("No .env file found, using default environment variables. If needed, please create a .env file and set the relevant variables.") } - common.SetupLogger() - // 加载环境变量 common.InitEnv() + common.SetupLogger() + // Initialize model settings ratio_setting.InitRatioSettings()