mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-10 15:49:29 +08:00
fix(toolUsePlugin): handle empty tools case in prompt generation (#10111)
Return null when no tools are available and skip tool section in system prompt
This commit is contained in:
parent
871565c687
commit
5e19e7ac6c
@ -156,8 +156,10 @@ Assistant: The population of Shanghai is 26 million, while Guangzhou has a popul
|
|||||||
/**
|
/**
|
||||||
* 构建可用工具部分(提取自 Cherry Studio)
|
* 构建可用工具部分(提取自 Cherry Studio)
|
||||||
*/
|
*/
|
||||||
function buildAvailableTools(tools: ToolSet): string {
|
function buildAvailableTools(tools: ToolSet): string | null {
|
||||||
const availableTools = Object.keys(tools)
|
const availableTools = Object.keys(tools)
|
||||||
|
if (availableTools.length === 0) return null
|
||||||
|
const result = availableTools
|
||||||
.map((toolName: string) => {
|
.map((toolName: string) => {
|
||||||
const tool = tools[toolName]
|
const tool = tools[toolName]
|
||||||
return `
|
return `
|
||||||
@ -172,7 +174,7 @@ function buildAvailableTools(tools: ToolSet): string {
|
|||||||
})
|
})
|
||||||
.join('\n')
|
.join('\n')
|
||||||
return `<tools>
|
return `<tools>
|
||||||
${availableTools}
|
${result}
|
||||||
</tools>`
|
</tools>`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,6 +183,7 @@ ${availableTools}
|
|||||||
*/
|
*/
|
||||||
function defaultBuildSystemPrompt(userSystemPrompt: string, tools: ToolSet): string {
|
function defaultBuildSystemPrompt(userSystemPrompt: string, tools: ToolSet): string {
|
||||||
const availableTools = buildAvailableTools(tools)
|
const availableTools = buildAvailableTools(tools)
|
||||||
|
if (availableTools === null) return userSystemPrompt
|
||||||
|
|
||||||
const fullPrompt = DEFAULT_SYSTEM_PROMPT.replace('{{ TOOL_USE_EXAMPLES }}', DEFAULT_TOOL_USE_EXAMPLES)
|
const fullPrompt = DEFAULT_SYSTEM_PROMPT.replace('{{ TOOL_USE_EXAMPLES }}', DEFAULT_TOOL_USE_EXAMPLES)
|
||||||
.replace('{{ AVAILABLE_TOOLS }}', availableTools)
|
.replace('{{ AVAILABLE_TOOLS }}', availableTools)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user