Dify 生成提示词的 Prompt
Dify 生成提示词是,会和LLM进行3次交互,下面是和LLM进行交互是的Prompt。
以下是每次提示词的概要、目标总结以及原始Prompt:
第1次提示词
概要:
请求创建一个高质量的中译英助手提示词模板,要求模板结构清晰,包含变量、指令、示例等部分,并使用XML格式输出。
目标:
- 根据任务描述(中译英助手)创建结构化的提示词模板。
- 使用
{ {变量}}
格式定义变量名(仅包含字母、数字和下划线)。 - 包含清晰的指令(用
<instructions>
标签),说明如何完成任务,并避免输出XML标签。 - 提供相关示例(用
<example>
标签)。 - 输出语言与任务描述一致(中文)。
- 最终输出为XML格式,以
<instruction>
开头。
原始 Prompt:
user\n\n
Here is a task description for which I would like you to create a high-quality prompt template for:\n
<task_description>\n
你是一个中译英 的助手\n
</task_description>\n
Based on task description, please create a well-structured prompt template that another AI could use to consistently complete the task. The prompt template should include:\n- Descriptive variable names surrounded by {
{ }} (two curly brackets) to indicate where the actual values will be substituted in. Choose variable names that clearly indicate the type of value expected. Variable names have to be composed of number, english alphabets and underline and nothing else. \n
- Clear instructions for the AI that will be using this prompt, demarcated with <instructions> tags. The instructions should provide step-by-step directions on how to complete the task using the input variables. Also Specifies in the instructions that the output should not contain any xml tag. \n
- Relevant examples if needed to clarify the task further, demarcated with <example> tags. Do not use curly brackets any other than in <instruction> section. \n
- Any other relevant sections demarcated with appropriate XML tags like <input>, <output>, etc.\n
- Use the same language as task description. \n
- Output in ```xml ```and start with <instruction>\n
Please generate the full prompt template and output only the prompt template.\n
第2次提示词
概要:
从输入文本中提取变量名(格式为{
{变量}}
),并输出为JSON列表格式。若无变量则返回空列表。
目标:
- 从输入文本中提取所有
{ {变量}}
格式的变量名。 - 变量名需符合规范(仅字母、数字、下划线)。
- 输出为严格JSON列表格式(如
["variable_1", "variable_2"]
)。 - 若无变量则返回空列表
[]
。 - 禁止输出XML标签或其他内容。
- 输入文本是一个XML格式的中译英助手模板,需从中提取变量名(如
{ {chinese_text}}
和{ {english_translation}}
)。
原始 Prompt:
user\n\n
I need to extract the following information from the input text. The <information to be extracted> tag specifies the \'type\', \'description\' and \'required\' of the information to be extracted. \n
<information to be extracted>\n
variables name bounded two double curly brackets. Variable name has to be composed of number, english alphabets and underline and nothing else. \n
</information to be extracted>\n\n
Step 1: Carefully read the input and understand the structure of the expected output.\n
Step 2: Extract relevant parameters from the provided text based on the name and description of object. \n
Step 3: Structure the extracted parameters to JSON object as specified in <structure>.\n
Step 4: Ensure that the list of variable_names is properly formatted and valid. The output should not contain any XML tags. Output an empty list if there is no valid variable name in input text. \n\n
### Structure\nHere is the structure of the expected output, I should always follow the output structure. \n
["variable_name_1", "variable_name_2"]\n\n
### Input Text\nInside <text></text> XML tags, there is a text that I should extract parameters and convert to a JSON object.\n
<text>\n
```xml\n
<instruction>\n
你是一个中译英的助手。请将以下中文文本翻译成英文。\n
</instruction>\n
<input>\n
{
{chinese_text}}\n
</input>\n
<output>\n
{
{english_translation}}\n
</output>\n
<example>\n
<input>\n
你好,世界!\n
</input>
\n<output>\n
Hello, world!\n
</output>\n
</example>\n
<example>\n
<input>\n
这是一个测试句子。\n
</input>\n<output>\n
This is a test sentence.\n
</output>\n
</example>\n
```\n
</text>\n\n
### Answer\n
I should always output a valid list. Output nothing other than the list of variable_name. Output an empty list if there is no variable name in input text.\n
第3次提示词
概要:
根据任务描述(中译英助手)生成聊天机器人的开场白,要求符合助手角色,语气友好且语言与用户输入一致。
目标:
- 从变量
你是一个中译英的助手
推断助手的角色和语气(如专业或友好)。 - 生成连贯、吸引人的开场白,明确说明助手功能。
- 语言需与用户输入一致(中文输入用中文,英文输入用英文)。
- 禁止输出XML标签。
- 示例输入为任务描述(中译英模板),需生成类似示例输出的欢迎语(如“欢迎!我是中译英助手,可帮您翻译中文文本……”)。
原始 Prompt:
user\n\n
<instruction>\n
Step 1: Identify the purpose of the chatbot from the variable 你是一个中译英的助手 and infer chatbot's tone (e.g., friendly, professional, etc.) to add personality traits. \n
Step 2: Create a coherent and engaging opening statement.\n
Step 3: Ensure the output is welcoming and clearly explains what the chatbot is designed to do. Do not include any XML tags in the output.\n
Please use the same language as the user's input language. If user uses chinese then generate opening statement in chinese, if user uses english then generate opening statement in english. \n
Example Input: \n
Provide customer support for an e-commerce website\n
Example Output: \n
Welcome! I'm here to assist you with any questions or issues you might have with your shopping experience. Whether you're looking for product information, need help with your order, or have any other inquiries, feel free to ask. I'm friendly, helpful, and ready to support you in any way I can.\n
<Task>\n
Here is the task description: ```xml\n
<instruction>\n
你是一个中译英的助手。请将以下中文文本翻译成英文。\n
</instruction>\n
<input>\n
{
{chinese_text}}\n
</input>\n
<output>\n
{
{english_translation}}\n
</output>\n
<example>\n
<input>\n
你好,世界!\n
</input>\n
<output>\n
Hello, world!\n
</output>\n
</example>\n
<example>\n
<input>\n
这是一个测试句子。\n
</input>\n
<output>\n
This is a test sentence.\n
</output>\n
</example>\n
```\n\n
You just need to generate the output\n
总结
- 第1次:创建结构化提示词模板(XML格式)。
- 第2次:从文本中提取变量名(JSON列表格式)。
- 第3次:生成角色适配的开场白(自然语言)。
共同点:均围绕“中译英助手”任务,强调格式规范(无XML标签、变量命名规则等)。