fix: SearXNG max_results 配置被 AI 参数覆盖
根因: ?? 空值回退链让 AI 传入的 max_results:10 直接生效, 配置面板的 30 被跳过 修复: 改用 Math.max() 让配置面板作为下限, AI 参数不得低于配置值 同时修复 fetch_top 的相同问题
This commit is contained in:
@@ -252,18 +252,18 @@ export class WebSearchTool implements IMetonaTool {
|
|||||||
// 读取 SearXNG 配置(提前读取,使工具参数默认值与配置一致)
|
// 读取 SearXNG 配置(提前读取,使工具参数默认值与配置一致)
|
||||||
const searxngConfig = this.readSearXNGConfig();
|
const searxngConfig = this.readSearXNGConfig();
|
||||||
|
|
||||||
// max_results: 工具参数 > 配置面板 > 默认 30。取较大值保证配置面板的下限约束
|
// max_results: 配置面板为下限,AI 参数不得低于配置值,上限 30
|
||||||
const argMaxResults = (args.max_results as number) ?? undefined;
|
const argMaxResults = (args.max_results as number) ?? undefined;
|
||||||
const cfgMaxResults = searxngConfig.max_results > 0 ? searxngConfig.max_results : undefined;
|
const cfgMaxResults = searxngConfig.max_results > 0 ? searxngConfig.max_results : undefined;
|
||||||
const maxResults = Math.min(30, Math.max(1, argMaxResults ?? cfgMaxResults ?? 30));
|
const maxResults = Math.min(30, Math.max(1, argMaxResults ?? 30, cfgMaxResults ?? 0));
|
||||||
|
|
||||||
const timeRange = (args.time_range as string) ?? '';
|
const timeRange = (args.time_range as string) ?? '';
|
||||||
const enhanceSnippets = (args.enhance_snippets as boolean) ?? true;
|
const enhanceSnippets = (args.enhance_snippets as boolean) ?? true;
|
||||||
|
|
||||||
// fetch_top: 工具参数 > 配置面板 > 默认 5。取较大值保证配置面板的下限约束
|
// fetch_top: 配置面板为下限,AI 参数不得低于配置值,上限 8
|
||||||
const argFetchTop = (args.fetch_top as number) ?? undefined;
|
const argFetchTop = (args.fetch_top as number) ?? undefined;
|
||||||
const cfgFetchCount = searxngConfig.fetch_count > 0 ? searxngConfig.fetch_count : undefined;
|
const cfgFetchCount = searxngConfig.fetch_count > 0 ? searxngConfig.fetch_count : undefined;
|
||||||
const fetchTop = Math.min(8, Math.max(3, argFetchTop ?? cfgFetchCount ?? 5));
|
const fetchTop = Math.min(8, Math.max(3, argFetchTop ?? 5, cfgFetchCount ?? 0));
|
||||||
|
|
||||||
// 缓存检查(缓存 key 含 SearXNG 模式,避免切换后返回旧缓存)
|
// 缓存检查(缓存 key 含 SearXNG 模式,避免切换后返回旧缓存)
|
||||||
const cacheKey = `${searxngConfig.enabled ? 'searxng' : 'builtin'}:${normalizeUrl(query).toLowerCase()}`;
|
const cacheKey = `${searxngConfig.enabled ? 'searxng' : 'builtin'}:${normalizeUrl(query).toLowerCase()}`;
|
||||||
|
|||||||
Reference in New Issue
Block a user