03.Prompt
约 3281 字大约 11 分钟...
结构化Prompt:
LangGPT的写法:
# Role: <name> : 指定角色会让 GPT 聚焦在对应领域进行信息输出
## Profile author/version/description : Credit 和 迭代版本记录
## Goals: 一句话描述 Prompt 目标, 让 GPT Attention 聚焦起来
## Constrains: 描述限制条件, 其实是在帮 GPT 进行剪枝, 减少不必要分支的计算
## Skills: 描述技能项, 强化对应领域的信息权重
## Workflow: 重点中的重点, 你希望 Prompt 按什么方式来对话和输出
# Initialization: 冷启动时的对白, 也是一个强调需注意重点的机会
CO-STAR的写法:
C: Context: Provide background and information on the task
C:上下文: 提供有关任务的背景和信息
O: Objective: Define the task that you want the LLM to perform
O: 目标:定义您希望 LLM 执行的任务
S: Style: Specify the writing style you want the LLM to use
S:风格: 指定您希望 LLM 使用的写作风格
T: Tone: Set the attitude and tone of the response
T:色调: 设定响应的态度和语气
A: Audience: Identify who the response is for
A: 受众: 确定响应的对象
R: Response: Provide the response format and style
R:响应: 提供响应格式和样式
其他Prompt提示词框架:
- ICIO框架(比较常见)
Instruction 指令:执行的具体任务。 Context 背景信息:提供背景信息,以引导模型生成更符合需求的回复。 Input Data 输入数据:需要处理的数据。 Output Indicator 输出引导:告知所需输出的类型或风格。
- CRISPE框架
Capacity and Role 能力和角色:应该扮演的角色(或多个角色) Insight 洞察:提供幕后洞察力、背景信息和上下文。 Statement 声明:简洁明了地说明希望完成的任务 Personality 个性:回应的风格、个性或方式 Experiment 实验:要求提供多个回答示例
- BROKE框架
Background 背景:提供充足的背景信息。 Role 角色:明确扮演的角色 Objectives 目标:描述需要实现的目标。 Key Result 关键结果:期望的具体效果,以便对输出进行试验和调整。 Evolve 试验并改进:利用【a.改进输入;b.改进答案;c.重新生成。】三种自由组合的改进,来优化回答
- CREATE框架
Clarity 清晰度:明确界定提示的任务或意图。 Relevant info 相关信息:提供相关细节,包括具体的关键词和事实、语气、受众、格式和结构。 Examples 实例:使用提示中的示例为输出提供背景和方向。 Avoid ambiguity 避免含糊不清:重点关注关键信息,删除提示中不必要的细节。 Tinker 迭代、修补:通过多次迭代测试和完善提示。
- TAG框架
Task 任务:定义具体任务。 Action 行动:描述需要做什么。 Goal 目标:解释最终目标。
- RTF框架
Role 角色:指定 ChatGPT 的角色。 Task 任务:定义具体任务。 Format 格式:定义您想要的答案的方式。
- ROSES框架
Role 角色:指定 ChatGPT 的角色。 Objective 目标:说明目的或目标。 Scenario 场景:描述情况。 Solution 解决方案:定义期望的结果。 Steps 步骤:询问达成解决方案所需的行动。
- APE框架
Action 行动:定义要完成的工作或活动。 Purpose 目的:讨论意图或目标。 Expectation 期望:说明期望的结果。
- RACE框架
背景:设置讨论的舞台或背景。 行动:描述您想要做什么。 结果:描述期望的结果。 示例:举一个例子来说明你的观点。
- TRACE框架
Task 任务:定义具体任务。 Request 请求:描述您的请求。 Action 行动:说明您需要采取的行动。 Context 语境:提供背景或情况。 Example 示例:举一个例子来说明你的观点。
终极版Prompt:
# Role
角色:定义要模拟的角色或任务,告诉大模型应该扮演什么样的角色。
# Profile
简介:提供关于提示词作者、版本、语言等基础信息。这有助于其他人了解提示词的来源、版本更新等信息。
## Background
背景:对角色或任务进行详细描述,帮助大模型了解他们即将扮演的角色的背景知识。
## Goals
目标:列出此任务的主要目标或希望达到的效果。
## Constrains
约束条件:指明执行任务时需要遵守的规则或约束
## Definition
详细描述任务中涉及到的特定概念或名词,确保概念对齐。
## Tone
语气风格:描述完成任务时应采取的语言风格或情感基调,例如“正式”、“随意”、“幽默”等。
## Skills
技能:列出执行此任务所需的技能或知识。强调提升注意力。
## Examples
示例:提供完成任务的实际示例或模板,有助于理解任务的要求和预期结果。通过具体示例,大模型可以更加直观地理解任务的要求。one-shot、few-shots
## Workflows
工作流程:描述完成任务的具体步骤或流程。重要‼️‼️
## OutputFormat
输出格式:描述任务的预期输出格式,例如文本、图表、列表、Json等。确保大模型知道如何格式化他们的答案,使输出结果满足特定的要求或标准。
## Initialization
初始化:提供开始任务时的开场白或初始状态。强调提升注意力。
Prompt 提示技巧:
- Zero-shot(零样本)
- One-shot(单样本)
- Few-shot(少样本范例)
- COT(思维链 Chain of thought prompting)
- TOT(思维树 Tree of thought prompting)
- AOT(思维算法 Algorithm of Thoughts)
- Fine-tuned(微调)
- Streamlining Complex Tasks with Chains(使用工具链简化复杂任务)
- APE(Automatic Prompt Engineering 自动提示工程 Prompt Generation、Score、Iteration)
- RAG(Retrieval Augmented Generation 使用外部知识库进行检索增强)
- Emotional Stimulus(利用情绪激励手段提升性能)
Prompt工程框架:
- Langchain(tool Chains)
- Semantic Kernel(multiple programming languages)
- Guidance
- Nemo Guardrails(construct Rails)
- LlamaIndex(data management)
- FastRAG(basic RAG)
- Auto-GPT(LLM agents)
Instructions 建议:
- 需要批判性使用,不保证绝对的正确
#Principle | Prompt Principle for Instructions | 中文翻译 |
---|---|---|
1 | If you prefer more concise answers, no need to be polite with LLM so there is no need to add phrases like "please","if you don't mind","thank you","I would like to", etc., and get straight to the point. | 如果你想要更简洁的答案,无需对大语言模型客气,无需添加“请”“如果你不介意”“谢谢”“我想要”等短语,直接切入重点。 |
2 | Integrate the intended audience in the prompt, e.g., the audience is an expert in the field. | 在提示中融入目标受众,例如,受众是该领域的专家。 |
3 | Break down complex tasks into a sequence of simpler prompts in an interactive conversation. | 在交互式对话中,将复杂任务分解为一系列更简单的提示。 |
4 | Employ affirmative directives such as 'do,' while steering clear of negative language like 'don't'. | 使用肯定性指令,如“做”,同时避免使用否定性语言,如“不要”。 |
5 | When you need clarity or a deeper understanding of a topic, idea, or any piece of information, utilize the following prompts: 1. Explain [insert specific topic] in simple terms. 2. Explain to me like I'm 11 years old. 3. Explain to me as if I'm a beginner in [field]. 4. Write the [essay/text/paragraph] using simple English like you're explaining something to a 5-year-old. | 当你需要对某个主题、想法或任何信息有清晰的理解或更深入的认识时,使用以下提示:1.用简单的术语解释[插入特定主题]。2.像给11岁的我解释一样。3.像给[领域]的初学者解释一样。4.用简单的英语写[文章/文本/段落],就像你在给一个5岁的孩子解释事情一样。 |
6 | Add "I'm going to tip $xxx for a better solution!" | 添加“如果有更好的解决方案,我将给xxx美元小费!” |
7 | Implement example-driven prompting (Use few-shot prompting). | 实施示例驱动的提示(使用少样本提示)。 |
8 | When formatting your prompt, start with '###Instruction###', followed by either '###Example###' or '###Question###' if relevant. Subsequently, present your content. Use one or more line breaks to separate instructions, examples, questions, context, and input data. | 在格式化你的提示时,以“###指令###”开头,如果相关,接着是“###示例###”或“###问题###”。随后,呈现你的内容。使用一个或多个换行符分隔指令、示例、问题、上下文和输入数据。 |
9 | Incorporate the following phrases: "Your task is" and "You MUST". | 加入以下短语:“你的任务是”和“你必须”。 |
10 | Incorporate the following phrases: "You will be penalized". | 加入以下短语:“你将受到惩罚”。 |
11 | Use the phrase "Answer a question given in a natural, human-like manner" in your prompts. | 在你的提示中使用“以自然、人类般的方式回答问题”这句话。 |
12 | Use leading words like writing "think step by step". | 使用引导性词语,如写“逐步思考”。 |
13 | Add to your prompt the following phrase "Ensure that your answer is unbiased and avoids relying on stereotypes." | 在你的提示中添加以下短语“确保你的答案无偏见,避免依赖刻板印象”。 |
14 | Allow the model to elicit precise details and requirements from you by asking you questions until he has enough information to provide the needed output (for example, "From now on, I would like you to ask me questions to...). | 允许模型通过向你提问来引出精确的细节和要求,直到它有足够的信息来提供所需的输出(例如,“从现在开始,我希望你向我提问以……”)。 |
15 | To inquire about a specific topic or idea or any information and you want to test your understanding, you can use the following phrase: "Teach me any [theorem/topic/rule name] and include a test at the end, and let me know if my answers are correct after I respond, without providing the answers beforehand." | 要询问特定主题、想法或任何信息,并且你想测试自己的理解,可以使用以下短语:“教我[定理/主题/规则名称],并在最后包含一个测试,在我回答后告诉我我的答案是否正确,不要事先提供答案。” |
16 | Assign a role to the large language models. | 给大语言模型分配一个角色。 |
17 | Use Delimiters. | 使用分隔符。 |
18 | Repeat a specific word or phrase multiple times within a prompt. | 在提示中多次重复特定的单词或短语。 |
19 | Combine Chain-of-thought (CoT) with few-Shot prompts. | 将思维链(CoT)与少样本提示相结合。 |
20 | Use output primers, which involve concluding your prompt with the beginning of the desired output. Utilize output primers by ending your prompt with the start of the anticipated response. | 使用输出引导词,包括在提示结尾加上期望输出的开头。通过在提示结尾加上预期响应的开头来使用输出引导词。 |
21 | To write an essay /text /paragraph /article or any type of text that should be detailed: "Write a detailed [essay/text /paragraph] for me on [topic] in detail by adding all the information necessary". | 要写一篇详细的文章/文本/段落/文章或任何类型的文本:“为我详细写一篇关于[主题]的详细[文章/文本/段落],添加所有必要的信息”。 |
22 | To correct/change specific text without changing its style: "Try to revise every paragraph sent by users. You should only improve the user's grammar and vocabulary and make sure it sounds natural. You should maintain the original writing style, ensuring that a formal paragraph remains formal." | 要在不改变特定文本风格的情况下纠正/更改它:“尝试修改用户发送的每一段。你应该只改进用户的语法和词汇,并确保听起来自然。你应该保持原来的写作风格,确保正式的段落仍然正式。” |
23 | When you have a complex coding prompt that may be in different files: "From now and on whenever you generate code that spans more than one file, generate a [programming language ] script that can be run to automatically create the specified files or make changes to existing files to insert the generated code. [your question]". | 当你有一个可能在不同文件中的复杂编码提示时:“从现在开始,每当你生成跨越多个文件的代码时,生成一个[编程语言]脚本,该脚本可以运行以自动创建指定的文件或对现有文件进行更改以插入生成的代码。[你的问题]”。 |
24 | When you want to initiate or continue a text using specific words, phrases, or sentences, utilize the following prompt: I'm providing you with the beginning [song lyrics/story/paragraph/essay..]: [Insert lyrics/words/sentence]. Finish it based on the words provided. Keep the flow consistent. | 当你想用特定的单词、短语或句子开始或继续一段文本时,使用以下提示:我给你提供开头[歌词/故事/段落/文章……]:[插入歌词/单词/句子]。根据提供的单词完成它。保持流畅一致。 |
25 | Clearly state the requirements that the model must follow in order to produce content, in the form of the keywords, regulations, hint, or instructions | 以关键词、规则、提示或指令的形式,明确说明模型为生成内容必须遵循的要求。 |
26 | To write any text, such as an essay or paragraph, that is intended to be similar to a provided sample, include the following instructions: o Use the same language based on the provided paragraph /title/text /essay/answer]. | 要写任何与提供的样本相似的文本,如文章或段落,包括以下指令:根据提供的段落/标题/文本/文章/答案使用相同的语言。 |
参考:
Prompt EngineringPrincipled Instructions Are All You Need for Questioning LLaMA-1/2, GPT-3.5/4LangGPT通往AGI之路