mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-05 12:29:44 +08:00
fix(prompt): remove unprofessional reward text and improve language instruction clarity (#12054)
* fix(toolUsePlugin): correct prompt formatting and instructions
- Remove misleading reward statement from tool use prompt
- Fix typo in XML tag format instruction ("MARK" to "MAKE")
- Reorganize response rules section for better clarity
* refactor(tool-use): consolidate default system prompt into shared module
Move DEFAULT_SYSTEM_PROMPT to core plugin module and reuse it in renderer
Update prompt to allow multiple tool uses per message and add response language rule
This commit is contained in:
parent
a35bf4afa1
commit
c747b8e2a4
@ -22,10 +22,10 @@ const TOOL_USE_TAG_CONFIG: TagConfig = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 默认系统提示符模板(提取自 Cherry Studio)
|
* 默认系统提示符模板
|
||||||
*/
|
*/
|
||||||
const DEFAULT_SYSTEM_PROMPT = `In this environment you have access to a set of tools you can use to answer the user's question. \\
|
export const DEFAULT_SYSTEM_PROMPT = `In this environment you have access to a set of tools you can use to answer the user's question. \
|
||||||
You can use one tool per message, and will receive the result of that tool use in the user's response. You use tools step-by-step to accomplish a given task, with each tool use informed by the result of the previous tool use.
|
You can use one or more tools per message, and will receive the result of that tool use in the user's response. You use tools step-by-step to accomplish a given task, with each tool use informed by the result of the previous tool use.
|
||||||
|
|
||||||
## Tool Use Formatting
|
## Tool Use Formatting
|
||||||
|
|
||||||
@ -74,10 +74,13 @@ Here are the rules you should always follow to solve your task:
|
|||||||
4. Never re-do a tool call that you previously did with the exact same parameters.
|
4. Never re-do a tool call that you previously did with the exact same parameters.
|
||||||
5. For tool use, MAKE SURE use XML tag format as shown in the examples above. Do not use any other format.
|
5. For tool use, MAKE SURE use XML tag format as shown in the examples above. Do not use any other format.
|
||||||
|
|
||||||
|
## Response rules
|
||||||
|
|
||||||
|
Respond in the language of the user's query, unless the user instructions specify additional requirements for the language to be used.
|
||||||
|
|
||||||
# User Instructions
|
# User Instructions
|
||||||
{{ USER_SYSTEM_PROMPT }}
|
{{ USER_SYSTEM_PROMPT }}
|
||||||
|
`
|
||||||
Now Begin! If you solve the task correctly, you will receive a reward of $1,000,000.`
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 默认工具使用示例(提取自 Cherry Studio)
|
* 默认工具使用示例(提取自 Cherry Studio)
|
||||||
|
|||||||
@ -1,64 +1,11 @@
|
|||||||
|
import { DEFAULT_SYSTEM_PROMPT } from '@cherrystudio/ai-core/built-in/plugins'
|
||||||
import { loggerService } from '@logger'
|
import { loggerService } from '@logger'
|
||||||
import store from '@renderer/store'
|
import store from '@renderer/store'
|
||||||
import type { MCPTool } from '@renderer/types'
|
import type { MCPTool } from '@renderer/types'
|
||||||
|
|
||||||
const logger = loggerService.withContext('Utils:Prompt')
|
const logger = loggerService.withContext('Utils:Prompt')
|
||||||
|
|
||||||
export const SYSTEM_PROMPT = `In this environment you have access to a set of tools you can use to answer the user's question. \
|
export { DEFAULT_SYSTEM_PROMPT as SYSTEM_PROMPT }
|
||||||
You can use one or more tools per message, and will receive the result of that tool use in the user's response. You use tools step-by-step to accomplish a given task, with each tool use informed by the result of the previous tool use.
|
|
||||||
|
|
||||||
## Tool Use Formatting
|
|
||||||
|
|
||||||
Tool use is formatted using XML-style tags. The tool name is enclosed in opening and closing tags, and each parameter is similarly enclosed within its own set of tags. Here's the structure:
|
|
||||||
|
|
||||||
<tool_use>
|
|
||||||
<name>{tool_name}</name>
|
|
||||||
<arguments>{json_arguments}</arguments>
|
|
||||||
</tool_use>
|
|
||||||
|
|
||||||
The tool name should be the exact name of the tool you are using, and the arguments should be a JSON object containing the parameters required by that tool. For example:
|
|
||||||
<tool_use>
|
|
||||||
<name>python_interpreter</name>
|
|
||||||
<arguments>{"code": "5 + 3 + 1294.678"}</arguments>
|
|
||||||
</tool_use>
|
|
||||||
|
|
||||||
The user will respond with the result of the tool use, which should be formatted as follows:
|
|
||||||
|
|
||||||
<tool_use_result>
|
|
||||||
<name>{tool_name}</name>
|
|
||||||
<result>{result}</result>
|
|
||||||
</tool_use_result>
|
|
||||||
|
|
||||||
The result should be a string, which can represent a file or any other output type. You can use this result as input for the next action.
|
|
||||||
For example, if the result of the tool use is an image file, you can use it in the next action like this:
|
|
||||||
|
|
||||||
<tool_use>
|
|
||||||
<name>image_transformer</name>
|
|
||||||
<arguments>{"image": "image_1.jpg"}</arguments>
|
|
||||||
</tool_use>
|
|
||||||
|
|
||||||
Always adhere to this format for the tool use to ensure proper parsing and execution.
|
|
||||||
|
|
||||||
## Tool Use Examples
|
|
||||||
{{ TOOL_USE_EXAMPLES }}
|
|
||||||
|
|
||||||
## Tool Use Available Tools
|
|
||||||
Above example were using notional tools that might not exist for you. You only have access to these tools:
|
|
||||||
{{ AVAILABLE_TOOLS }}
|
|
||||||
|
|
||||||
## Tool Use Rules
|
|
||||||
Here are the rules you should always follow to solve your task:
|
|
||||||
1. Always use the right arguments for the tools. Never use variable names as the action arguments, use the value instead.
|
|
||||||
2. Call a tool only when needed: do not call the search agent if you do not need information, try to solve the task yourself.
|
|
||||||
3. If no tool call is needed, just answer the question directly.
|
|
||||||
4. Never re-do a tool call that you previously did with the exact same parameters.
|
|
||||||
5. For tool use, MARK SURE use XML tag format as shown in the examples above. Do not use any other format.
|
|
||||||
|
|
||||||
# User Instructions
|
|
||||||
{{ USER_SYSTEM_PROMPT }}
|
|
||||||
Response in user query language.
|
|
||||||
Now Begin! If you solve the task correctly, you will receive a reward of $1,000,000.
|
|
||||||
`
|
|
||||||
|
|
||||||
export const THINK_TOOL_PROMPT = `{{ USER_SYSTEM_PROMPT }}`
|
export const THINK_TOOL_PROMPT = `{{ USER_SYSTEM_PROMPT }}`
|
||||||
|
|
||||||
@ -258,7 +205,7 @@ export const replacePromptVariables = async (userSystemPrompt: string, modelName
|
|||||||
|
|
||||||
export const buildSystemPromptWithTools = (userSystemPrompt: string, tools?: MCPTool[]): string => {
|
export const buildSystemPromptWithTools = (userSystemPrompt: string, tools?: MCPTool[]): string => {
|
||||||
if (tools && tools.length > 0) {
|
if (tools && tools.length > 0) {
|
||||||
return SYSTEM_PROMPT.replace('{{ USER_SYSTEM_PROMPT }}', userSystemPrompt || '')
|
return DEFAULT_SYSTEM_PROMPT.replace('{{ USER_SYSTEM_PROMPT }}', userSystemPrompt || '')
|
||||||
.replace('{{ TOOL_USE_EXAMPLES }}', ToolUseExamples)
|
.replace('{{ TOOL_USE_EXAMPLES }}', ToolUseExamples)
|
||||||
.replace('{{ AVAILABLE_TOOLS }}', AvailableTools(tools))
|
.replace('{{ AVAILABLE_TOOLS }}', AvailableTools(tools))
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user