feat: 百度云千帆联网搜索完整支持

为百度云千帆模型添加完整的联网搜索功能支持,包括搜索结果处理和引用格式适配。

## 主要修改

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
This commit is contained in:
GeorgeDong32 2025-12-17 23:47:05 +08:00
parent 6e637287a7
commit e38e963cc9
3 changed files with 30 additions and 0 deletions

View File

@ -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

View File

@ -661,6 +661,7 @@ export enum WebSearchSource {
QWEN = 'qwen',
HUNYUAN = 'hunyuan',
ZHIPU = 'zhipu',
BAIDU_CLOUD = 'baidu-cloud',
GROK = 'grok',
AISDK = 'ai-sdk'
}

View File

@ -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) => {