From ee7eee24da007f1026e0dc198c63b1ec5a66414a Mon Sep 17 00:00:00 2001 From: SuYao Date: Sat, 13 Dec 2025 22:58:59 +0800 Subject: [PATCH] fix: max search result (#11883) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: add search result limit * fix: typo * Update src/renderer/src/aiCore/utils/websearch.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix: test * Apply suggestion from @GeorgeDong32 Co-authored-by: George·Dong <98630204+GeorgeDong32@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: George·Dong <98630204+GeorgeDong32@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: George·Dong <98630204+GeorgeDong32@users.noreply.github.com> --- src/renderer/src/aiCore/utils/__tests__/websearch.test.ts | 2 +- src/renderer/src/aiCore/utils/websearch.ts | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/renderer/src/aiCore/utils/__tests__/websearch.test.ts b/src/renderer/src/aiCore/utils/__tests__/websearch.test.ts index fa5e3c3b3..5c95a664a 100644 --- a/src/renderer/src/aiCore/utils/__tests__/websearch.test.ts +++ b/src/renderer/src/aiCore/utils/__tests__/websearch.test.ts @@ -259,7 +259,7 @@ describe('websearch utils', () => { expect(result).toEqual({ xai: { - maxSearchResults: 50, + maxSearchResults: 30, returnCitations: true, sources: [{ type: 'web', excludedWebsites: [] }, { type: 'news' }, { type: 'x' }], mode: 'on' diff --git a/src/renderer/src/aiCore/utils/websearch.ts b/src/renderer/src/aiCore/utils/websearch.ts index 127636a50..14a99139b 100644 --- a/src/renderer/src/aiCore/utils/websearch.ts +++ b/src/renderer/src/aiCore/utils/websearch.ts @@ -9,6 +9,8 @@ import type { CherryWebSearchConfig } from '@renderer/store/websearch' import type { Model } from '@renderer/types' import { mapRegexToPatterns } from '@renderer/utils/blacklistMatchPattern' +const X_AI_MAX_SEARCH_RESULT = 30 + export function getWebSearchParams(model: Model): Record { if (model.provider === 'hunyuan') { return { enable_enhancement: true, citation: true, search_info: true } @@ -82,7 +84,7 @@ export function buildProviderBuiltinWebSearchConfig( const excludeDomains = mapRegexToPatterns(webSearchConfig.excludeDomains) return { xai: { - maxSearchResults: webSearchConfig.maxResults, + maxSearchResults: Math.min(webSearchConfig.maxResults, X_AI_MAX_SEARCH_RESULT), returnCitations: true, sources: [ {