mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-06 05:09:09 +08:00
refactor(aiCore): clean up KnowledgeSearchTool and searchOrchestrationPlugin
- Commented out unused parameters and code in the KnowledgeSearchTool to improve clarity and maintainability. - Removed the tool choice assignment in searchOrchestrationPlugin to streamline the logic. - Updated instructions handling in KnowledgeSearchTool to eliminate unnecessary fields.
This commit is contained in:
parent
6a1918deef
commit
0944faf8e5
@ -365,7 +365,7 @@ export const searchOrchestrationPlugin = (assistant: Assistant, topicId: string)
|
|||||||
getMessageContent(userMessage),
|
getMessageContent(userMessage),
|
||||||
topicId
|
topicId
|
||||||
)
|
)
|
||||||
params.toolChoice = { type: 'tool', toolName: 'builtin_knowledge_search' }
|
// params.toolChoice = { type: 'tool', toolName: 'builtin_knowledge_search' }
|
||||||
} else {
|
} else {
|
||||||
// on 模式:根据意图识别结果决定是否添加工具
|
// on 模式:根据意图识别结果决定是否添加工具
|
||||||
const needsKnowledgeSearch =
|
const needsKnowledgeSearch =
|
||||||
|
|||||||
@ -46,9 +46,7 @@ Call this tool to execute the search. You can optionally provide additional cont
|
|||||||
return {
|
return {
|
||||||
summary: 'No knowledge base configured for this assistant.',
|
summary: 'No knowledge base configured for this assistant.',
|
||||||
knowledgeReferences: [],
|
knowledgeReferences: [],
|
||||||
sources: '',
|
instructions: ''
|
||||||
instructions: '',
|
|
||||||
rawResults: []
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,9 +67,7 @@ Call this tool to execute the search. You can optionally provide additional cont
|
|||||||
return {
|
return {
|
||||||
summary: 'No search needed based on the query analysis.',
|
summary: 'No search needed based on the query analysis.',
|
||||||
knowledgeReferences: [],
|
knowledgeReferences: [],
|
||||||
sources: '',
|
instructions: ''
|
||||||
instructions: '',
|
|
||||||
rawResults: []
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,22 +105,20 @@ Call this tool to execute the search. You can optionally provide additional cont
|
|||||||
file: ref.file
|
file: ref.file
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const referenceContent = `\`\`\`json\n${JSON.stringify(knowledgeReferencesData, null, 2)}\n\`\`\``
|
// const referenceContent = `\`\`\`json\n${JSON.stringify(knowledgeReferencesData, null, 2)}\n\`\`\``
|
||||||
|
// TODO 在工具函数中添加搜索缓存机制
|
||||||
|
// const searchCacheKey = `${topicId}-${JSON.stringify(finalQueries)}`
|
||||||
|
// 可以在插件层面管理已搜索的查询,避免重复搜索
|
||||||
const fullInstructions = REFERENCE_PROMPT.replace(
|
const fullInstructions = REFERENCE_PROMPT.replace(
|
||||||
'{question}',
|
'{question}',
|
||||||
"Based on the knowledge references, please answer the user's question with proper citations."
|
"Based on the knowledge references, please answer the user's question with proper citations."
|
||||||
).replace('{references}', referenceContent)
|
).replace('{references}', 'knowledgeReferences:')
|
||||||
|
|
||||||
// 返回结果
|
// 返回结果
|
||||||
return {
|
return {
|
||||||
summary: `Found ${knowledgeReferencesData.length} relevant sources. Use [number] format to cite specific information.`,
|
summary: `Found ${knowledgeReferencesData.length} relevant sources. Use [number] format to cite specific information.`,
|
||||||
knowledgeReferences: knowledgeReferencesData,
|
knowledgeReferences: knowledgeReferencesData,
|
||||||
// sources: citationData
|
|
||||||
// .map((source) => `[${source.number}] ${source.title}\n${source.content}\nURL: ${source.url}`)
|
|
||||||
// .join('\n\n'),
|
|
||||||
instructions: fullInstructions
|
instructions: fullInstructions
|
||||||
// rawResults: citationData
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// 返回空对象而不是抛出错误,避免中断对话流程
|
// 返回空对象而不是抛出错误,避免中断对话流程
|
||||||
@ -132,7 +126,6 @@ Call this tool to execute the search. You can optionally provide additional cont
|
|||||||
summary: `Search failed: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
summary: `Search failed: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
||||||
knowledgeReferences: [],
|
knowledgeReferences: [],
|
||||||
instructions: ''
|
instructions: ''
|
||||||
// rawResults: []
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user