From 6048fd07917c33944716930314020f32b200b572 Mon Sep 17 00:00:00 2001 From: JustSong Date: Sun, 24 Dec 2023 16:12:02 +0800 Subject: [PATCH] refactor: only enable search when specified --- controller/relay-ali.go | 29 ++++++++++++++++------------ web/src/pages/Channel/EditChannel.js | 7 +++++++ 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/controller/relay-ali.go b/controller/relay-ali.go index accb28e9..7968bfb6 100644 --- a/controller/relay-ali.go +++ b/controller/relay-ali.go @@ -23,11 +23,11 @@ type AliInput struct { } type AliParameters struct { - TopP float64 `json:"top_p,omitempty"` - TopK int `json:"top_k,omitempty"` - Seed uint64 `json:"seed,omitempty"` - EnableSearch bool `json:"enable_search,omitempty"` - IncrementalOutput bool `json:"incremental_output,omitempty"` + TopP float64 `json:"top_p,omitempty"` + TopK int `json:"top_k,omitempty"` + Seed uint64 `json:"seed,omitempty"` + EnableSearch bool `json:"enable_search,omitempty"` + IncrementalOutput bool `json:"incremental_output,omitempty"` } type AliChatRequest struct { @@ -82,6 +82,8 @@ type AliChatResponse struct { AliError } +const AliEnableSearchModelSuffix = "-internet" + func requestOpenAI2Ali(request GeneralOpenAIRequest) *AliChatRequest { messages := make([]AliMessage, 0, len(request.Messages)) for i := 0; i < len(request.Messages); i++ { @@ -91,17 +93,20 @@ func requestOpenAI2Ali(request GeneralOpenAIRequest) *AliChatRequest { Role: strings.ToLower(message.Role), }) } + enableSearch := false + aliModel := request.Model + if strings.HasSuffix(aliModel, AliEnableSearchModelSuffix) { + enableSearch = true + aliModel = strings.TrimSuffix(aliModel, AliEnableSearchModelSuffix) + } return &AliChatRequest{ - Model: request.Model, + Model: aliModel, Input: AliInput{ Messages: messages, }, - Parameters: AliParameters{ // ChatGPT's parameters are not compatible with Ali's - // TopP: request.TopP, - // TopK: 50, - // //Seed: 0, - EnableSearch: true, - IncrementalOutput=true, + Parameters: AliParameters{ + EnableSearch: enableSearch, + IncrementalOutput: request.Stream, }, } } diff --git a/web/src/pages/Channel/EditChannel.js b/web/src/pages/Channel/EditChannel.js index 364da69d..b1c7ae62 100644 --- a/web/src/pages/Channel/EditChannel.js +++ b/web/src/pages/Channel/EditChannel.js @@ -70,6 +70,13 @@ const EditChannel = () => { break; case 17: localModels = ['qwen-turbo', 'qwen-plus', 'qwen-max', 'qwen-max-longcontext', 'text-embedding-v1']; + let withInternetVersion = []; + for (let i = 0; i < localModels.length; i++) { + if (localModels[i].startsWith('qwen-')) { + withInternetVersion.push(localModels[i] + '-internet'); + } + } + localModels = [...localModels, ...withInternetVersion]; break; case 16: localModels = ['chatglm_turbo', 'chatglm_pro', 'chatglm_std', 'chatglm_lite'];