From e38e963cc9d29744ba30b32c2fd659afc1a5cc99 Mon Sep 17 00:00:00 2001 From: GeorgeDong32 Date: Wed, 17 Dec 2025 23:47:05 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=99=BE=E5=BA=A6=E4=BA=91=E5=8D=83?= =?UTF-8?q?=E5=B8=86=E8=81=94=E7=BD=91=E6=90=9C=E7=B4=A2=E5=AE=8C=E6=95=B4?= =?UTF-8?q?=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 为百度云千帆模型添加完整的联网搜索功能支持,包括搜索结果处理和引用格式适配。 ## 主要修改 1. **OpenAIApiClient.ts**: 在collectWebSearchData函数中添加百度云搜索结果处理 - 检测chunk中的search_results字段 - 将搜索结果转换为标准格式 - 标记搜索来源为WebSearchSource.BAIDU_CLOUD 2. **types/index.ts**: 添加WebSearchSource.BAIDU_CLOUD枚举值 - 百度云搜索来源枚举值 - 与现有枚举保持一致 3. **citation.ts**: 在normalizeCitationMarks函数中添加百度云引用格式支持 - 处理^[1][4]^格式的引用标记 - 转换为标准[cite:N]格式 - 支持多个引用组合 ## 技术特性 - 支持百度云特殊引用格式:^[1][4]^ - 搜索结果在流结束时正确收集 - 引用标记正确转换和渲染 - 完全兼容现有架构 ## 测试 - 所有测试通过 (2467/2467) - citation和websearch相关测试全部通过 ## 相关Issue cherry-studio/issues/11958 --- .../legacy/clients/openai/OpenAIApiClient.ts | 11 +++++++++++ src/renderer/src/types/index.ts | 1 + src/renderer/src/utils/citation.ts | 18 ++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/src/renderer/src/aiCore/legacy/clients/openai/OpenAIApiClient.ts b/src/renderer/src/aiCore/legacy/clients/openai/OpenAIApiClient.ts index d839da8964..bed1169144 100644 --- a/src/renderer/src/aiCore/legacy/clients/openai/OpenAIApiClient.ts +++ b/src/renderer/src/aiCore/legacy/clients/openai/OpenAIApiClient.ts @@ -809,6 +809,17 @@ export class OpenAIAPIClient extends OpenAIBaseClient< } } + // Baidu Cloud web search + // @ts-ignore - search_results may not be in standard type definitions + if (context.provider?.id === 'baidu-cloud' && chunk.search_results && chunk.search_results.length > 0) { + hasBeenCollectedWebSearch = true + return { + // @ts-ignore - search_results may not be in standard type definitions + results: chunk.search_results, + source: WebSearchSource.BAIDU_CLOUD + } + } + // TODO: 放到AnthropicApiClient中 // // Other providers... // // @ts-ignore - web_search may not be in standard type definitions diff --git a/src/renderer/src/types/index.ts b/src/renderer/src/types/index.ts index 197d217793..5b79d3ce77 100644 --- a/src/renderer/src/types/index.ts +++ b/src/renderer/src/types/index.ts @@ -661,6 +661,7 @@ export enum WebSearchSource { QWEN = 'qwen', HUNYUAN = 'hunyuan', ZHIPU = 'zhipu', + BAIDU_CLOUD = 'baidu-cloud', GROK = 'grok', AISDK = 'ai-sdk' } diff --git a/src/renderer/src/utils/citation.ts b/src/renderer/src/utils/citation.ts index 8c97cbcde5..c4231c72c7 100644 --- a/src/renderer/src/utils/citation.ts +++ b/src/renderer/src/utils/citation.ts @@ -155,6 +155,24 @@ export function normalizeCitationMarks( } break } + case WebSearchSource.BAIDU_CLOUD: { + // 百度云格式: ^[1][4]^ → [cite:1], [cite:4] + applyReplacements(/\^\[(\d+(?:\]\[?\d+)*)\]\^/g, (match) => { + const citationNums = match[1] + .replace(/^\[/, '') + .replace(/\]$/g, '') + .split('][') + .map((num) => parseInt(num, 10)) + + const citations = citationNums + .filter((num) => citationMap.has(num)) + .map((num) => `[cite:${num}]`) + .join('') + + return citations + }) + break + } default: { // 简单数字格式: [N] → [cite:N] applyReplacements(/\[(\d+)\]/g, (match) => {