Dify 生成提示詞的 Prompt
- **第1次提示詞**
- **第2次提示詞**
- **第3次提示詞**
- 總結
Dify 生成提示詞是,會和LLM進行3次交互,下面是和LLM進行交互是的Prompt。
以下是每次提示詞的概要、目標總結以及原始Prompt:
第1次提示詞
概要:
請求創建一個高質量的中譯英助手提示詞模板,要求模板結構清晰,包含變量、指令、示例等部分,并使用XML格式輸出。
目標:
- 根據任務描述(中譯英助手)創建結構化的提示詞模板。
- 使用
{{變量}}
格式定義變量名(僅包含字母、數字和下劃線)。 - 包含清晰的指令(用
<instructions>
標簽),說明如何完成任務,并避免輸出XML標簽。 - 提供相關示例(用
<example>
標簽)。 - 輸出語言與任務描述一致(中文)。
- 最終輸出為XML格式,以
<instruction>
開頭。
原始 Prompt:
user\n\nHere 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\nI 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\nStep 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\nYou just need to generate the output\n
總結
- 第1次:創建結構化提示詞模板(XML格式)。
- 第2次:從文本中提取變量名(JSON列表格式)。
- 第3次:生成角色適配的開場白(自然語言)。
共同點:均圍繞“中譯英助手”任務,強調格式規范(無XML標簽、變量命名規則等)。