You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How do I add up a row of dollar amounts in Excel? I want to do this automatically for a whole sheet of rows with all the totals ending up on the right in a column called "Total".
Summarize the meeting notes.
Summarize the meeting notes in a single paragraph. Then write a markdown list of the speakers and each of their key points. Finally, list the next steps or action items suggested by the speakers, if any.
1.2 在SYSTEM Message 中要求LLM 扮演一个角色。例如:
SYSTEM
When I ask for help to write something, you will reply with a document that contains at least one joke or playful comment in every paragraph.
USER
Write a thank you note to my steel bolt vendor for getting the delivery in on time and in short notice. This made it possible for us to deliver an important order.
1.3 使用分隔符来包围特定含义的文本。例如:
USER
Summarize the text delimited by triple quotes with a haiku.
"""insert text here"""
这里就指示LLM 总结 """ 包围的文字。
1.4 指定完成任务的步骤。例如:
SYSTEM
Use the following step-by-step instructions to respond to user inputs.
Step 1 - The user will provide you with text in triple quotes. Summarize this text in one sentence with a prefix that says "Summary: ".
Step 2 - Translate the summary from Step 1 into Spanish, with a prefix that says "Translation: ".
USER
"""insert text here"""
SYSTEM
Answer in a consistent style.
USER
Teach me about patience.
ASSISTANT
The river that carves the deepest valley flows from a modest spring; the grandest symphony originates from a single note; the most intricate tapestry begins with a solitary thread.
USER
Teach me about the ocean.
1.6 指定响应的长度。例如:
USER
Summarize the text delimited by triple quotes in about 50 words.
"""insert text here"""
SYSTEM Use the provided articles delimited by triple quotes to answer questions. If the answer cannot be found in the articles, write "I could not find an answer."
USER <insert articles, each delimited by triple quotes>
Question: <insert question here>
SYSTEM 类型的 Message 指导 LLM 如何使用提供的参考文本,USER <> 中的内容是参考文本,这些文本可以从外部的知识库检索而来,例如外部的向量知识库。Question 则是真正用户的 query。
Zero-shot prompting means that the prompt used to interact with the model won't contain examples or demonstrations. The zero-shot prompt directly instructs the model to perform a task without any additional examples to steer it. 6
Few-shot Prompting
Few-shot prompting can be used as a technique to enable in-context learning where we provide demonstrations in the prompt to steer the model to better performance. The demonstrations serve as conditioning for subsequent examples where we would like the model to generate a response. 7
Chain-of-Thought Prompting
Introduced in Wei et al. (2022), chain-of-thought (CoT) prompting enables complex reasoning capabilities through intermediate reasoning steps. You can combine it with few-shot prompting to get better results on more complex tasks that require reasoning before responding. 8
LangChain中的prompt
在langchain中,Prompt 对象负责生成和格式化模型输入,还对每一轮交互定义了一个表示,称为 Messages。Message是Prompt的一部分,它们都包含 role 和 content 两个字段,对于不同类别的 message,还会包含其他定制的额外字段。 9
LLM 的训练过程,是让其大规模参数适配训练语料的模式。说对这种模式,才能打开LLM 知识的大门。与 LLM 对话时对模型的输入称为 Prompt,Prompt工程是一些说对prompt的最佳工程实践。
这实际是很容易理解:我们使用Google搜索时,一些搜索技巧可以提高搜索效率;同样的,使用LLM,也需要一些交互技巧。问对问题很关键。
Prompt 中的 Message
按照角色对 Message 分类
按照角色,openai 将 Message 分为了 developer、system、user、function、assistant、tool 六类,其中前四个是输入 LLM的,后两个则是LLM输出的。它们分别对 交互 有不同的作用和效果:
使用prompt的6个最佳实践
1. 清晰明确的指令
1.1 要包含尽可能多的细节信息。例如:
1.2 在SYSTEM Message 中要求LLM 扮演一个角色。例如:
1.3 使用分隔符来包围特定含义的文本。例如:
这里就指示LLM 总结 """ 包围的文字。
1.4 指定完成任务的步骤。例如:
这类信息适合在 SYSTEM Message 中指定。
1.5 提供示例。
通常提供通用的行为指导更高效,但是有时很难准确描述你要表达的意思,这个时候提供几个示例就容易一点,让模型模拟这种行为,当然,这种行为如果刚好是某几维特征,那么就能准确模拟。这种方法叫做
少样本提示(few-shot prompting)
。1.6 指定响应的长度。例如:
2. 提供参考文本
LLM 可能会自信地编造答案,提供参考示例文本可以减少虚假信息。例如:5
SYSTEM 类型的 Message 指导 LLM 如何使用提供的参考文本,USER
<>
中的内容是参考文本,这些文本可以从外部的知识库检索而来,例如外部的向量知识库。Question
则是真正用户的 query。3. 将复杂任务分解成多个简单的子任务
执行复杂任务出错的概率一般更高,复杂任务一般也能重新定义成由工作流串/并联起来的一些简单子任务,上一个工作流节点的执行结果作为下一个节点的输入。
todo
Prompt 中一些常见技术
Zero-shot Prompting
Few-shot Prompting
Chain-of-Thought Prompting
LangChain中的prompt
在langchain中,Prompt 对象负责生成和格式化模型输入,还对每一轮交互定义了一个表示,称为 Messages。Message是Prompt的一部分,它们都包含 role 和 content 两个字段,对于不同类别的 message,还会包含其他定制的额外字段。 9
ToolMessage
代表工具调用返回的结果,role 是tool
,除了 role 和 content外,还有tool_call_id
和artifact
两个字段。tool_call_id 就是字面意思,artifact 的内容是传递给 tool 的信息,不会传给 Model。 10HumanMessage
代表 User input:todoAIMessage
代表通过tools 查询 vector store:tooToolMessage
表示检索到的文档(retrieved documents):todo在对话型应用中,Message 对象常常作为上下文的一部分,传递给 ChatPromptTemplate,帮助构建更复杂的对话上下文。
Footnotes
https://community.openai.com/t/how-is-developer-message-better-than-system-prompt/1062784 ↩
https://python.langchain.com/v0.1/docs/modules/model_io/chat/message_types/ ↩
https://community.make.com/t/what-is-the-difference-between-system-user-and-assistant-roles-in-chatgpt/36160/3 ↩
https://community.openai.com/t/message-possible-type-role-tool-how-to-use-that/722442/5 ↩
https://platform.openai.com/docs/guides/prompt-engineering ↩
https://www.promptingguide.ai/techniques/zeroshot ↩
https://www.promptingguide.ai/techniques/fewshot ↩
https://www.promptingguide.ai/techniques/cot ↩
https://python.langchain.com/docs/concepts/messages/ ↩
https://python.langchain.com/docs/concepts/messages/#toolmessage ↩
The text was updated successfully, but these errors were encountered: