From 309c1d21659a7e530f69613657eadd4c1cc3b1ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9D=92=E6=A2=A7=E6=A0=96=E6=9B=A6?= <50487613+2256593769@users.noreply.github.com> Date: Tue, 19 May 2026 12:24:53 +0300 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20deepseek-stream.ts?= =?UTF-8?q?=E4=B8=AD=20SEARCH=20=E8=BF=87=E6=BB=A4=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/proxy/adapters/deepseek-stream.ts | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/main/proxy/adapters/deepseek-stream.ts b/src/main/proxy/adapters/deepseek-stream.ts index 173fbec..ee97d95 100644 --- a/src/main/proxy/adapters/deepseek-stream.ts +++ b/src/main/proxy/adapters/deepseek-stream.ts @@ -240,7 +240,10 @@ export class DeepSeekStreamHandler { ): void { const cleanedValue = content.replace(/FINISHED/g, '') // Always filter SEARCH keywords for thinking content - const filteredForSearch = cleanedValue.replace(/^(SEARCH|WEB_SEARCH|SEARCHING)\s*/i, '') + const shouldFilterSearch = this.webSearchEnabled || this.model.includes('search') + const filteredForSearch = shouldFilterSearch + ? cleanedValue.replace(/^(SEARCH|WEB_SEARCH|SEARCHING)\s*/i, '') + : cleanedValue const processedContent = isSearchSilentModel ? filteredForSearch.replace(/\[citation:(\d+)\]/g, '') : filteredForSearch.replace(/\[citation:(\d+)\]/g, '[$1]') @@ -352,6 +355,7 @@ export class DeepSeekStreamHandler { const isThinkingModel = this.model.includes('think') || this.model.includes('r1') || !!this.reasoningEffort const isFoldModel = (this.model.includes('fold') || this.model.includes('search') || this.webSearchEnabled) && !isThinkingModel const isSearchSilentModel = this.model.includes('search-silent') + const isSearchModel = this.model.includes('search') || this.webSearchEnabled return new Promise((resolve, reject) => { let buffer = '' @@ -386,7 +390,9 @@ export class DeepSeekStreamHandler { for (const fragment of fragments) { if (fragment.content) { let cleanedFragment = fragment.content.replace(/FINISHED/g, '') - cleanedFragment = cleanedFragment.replace(/^(SEARCH|WEB_SEARCH|SEARCHING)\s*/i, '') + if (isSearchModel) { + cleanedFragment = cleanedFragment.replace(/^(SEARCH|WEB_SEARCH|SEARCHING)\s*/i, '') + } if (fragment.type === 'THINK') { accumulatedThinkingContent += cleanedFragment } else if (fragment.type === 'ANSWER' || fragment.type === 'RESPONSE') { @@ -400,7 +406,9 @@ export class DeepSeekStreamHandler { for (const fragment of parsed.v) { if (fragment.content) { let cleanedFragment = fragment.content.replace(/FINISHED/g, '') - cleanedFragment = cleanedFragment.replace(/^(SEARCH|WEB_SEARCH|SEARCHING)\s*/i, '') + if (isSearchModel) { + cleanedFragment = cleanedFragment.replace(/^(SEARCH|WEB_SEARCH|SEARCHING)\s*/i, '') + } if (fragment.type === 'THINK') { currentPath = 'thinking' accumulatedThinkingContent += cleanedFragment @@ -437,7 +445,9 @@ export class DeepSeekStreamHandler { } if (Array.isArray(e.v)) { let cleanedValue = e.v.map((v: any) => v.content).join('').replace(/FINISHED/g, '') - cleanedValue = cleanedValue.replace(/^(SEARCH|WEB_SEARCH|SEARCHING)\s*/i, '') + if (isSearchModel) { + cleanedValue = cleanedValue.replace(/^(SEARCH|WEB_SEARCH|SEARCHING)\s*/i, '') + } if (currentPath === 'thinking') { accumulatedThinkingContent += cleanedValue } else if (currentPath === 'content') { @@ -449,7 +459,9 @@ export class DeepSeekStreamHandler { if (typeof parsed.v === 'string') { let cleanedValue = parsed.v.replace(/FINISHED/g, '') - cleanedValue = cleanedValue.replace(/^(SEARCH|WEB_SEARCH|SEARCHING)\s*/i, '') + if (isSearchModel) { + cleanedValue = cleanedValue.replace(/^(SEARCH|WEB_SEARCH|SEARCHING)\s*/i, '') + } if (currentPath === 'thinking') { accumulatedThinkingContent += cleanedValue } else if (currentPath === 'content') {