💡 If you're just getting started with OpenAI API, we recommend reading the Introduction and Quickstart tutorials first.
提示工程的工作原理
由于指令遵循模型的训练方式或它们训练的数据,有一些特定的提示格式特别有效,并且与手头的任务更好地结合。下面我们介绍了一些我们发现工作可靠的提示格式,但您可以随意探索可能最适合您的任务的不同格式。
经验法则和例子
注意:“ {text input here} ”是实际文本/上下文的占位符
1.使用最新型号
为获得最佳效果,我们通常建议使用最新、功能最强大的型号。截至 2022 年 11 月,最佳选择是用于文本生成的“text-davinci-003” 模型和用于代码生成的“code-davinci-002”模型。
2.将指令放在提示符的开头,用###或“””分隔指令和上下文
不太有效的❌:
Summarize the text below as a bullet point list of the most important points.
{text input here}
更好的✅:
Summarize the text below as a bullet point list of the most important points.
Text: """
{text input here}
"""
3. 对期望的背景、结果、长度、格式、风格等尽可能具体、描述和详细
具体说明上下文、结果、长度、格式、样式等
不太有效的❌:
Write a poem about OpenAI.
更好的✅:
Write a short inspiring poem about OpenAI, focusing on the recent DALL-E product launch (DALL-E is a text to image ML model) in the style of a {famous poet}
4. 通过示例(示例 1、示例 2 )阐明所需的输出格式。
不太有效的❌:
Extract the entities mentioned in the text below. Extract the following 4 entity types: company names, people names, specific topics and themes.
Text: {text}
显示并告知 – 当显示特定格式要求时,模型会更好地响应。这也使得以编程方式可靠地解析出多个输出变得更加容易。
更好的✅:
Extract the important entities mentioned in the text below. First extract all company names, then extract all people names, then extract specific topics which fit the content and finally extract general overarching themes
Desired format:
Company names: <comma_separated_list_of_company_names>
People names: -||-
Specific topics: -||-
General themes: -||-
Text: {text}
5. 从零镜头开始,然后是小镜头(示例),两者都不起作用,然后进行微调
✅ 零射击
Extract keywords from the below text.
Text: {text}
Keywords:
✅ Few-shot – 提供几个例子
Extract keywords from the corresponding texts below.
Text 1: Stripe provides APIs that web developers can use to integrate payment processing into their websites and mobile applications.
Keywords 1: Stripe, payment processing, APIs, web developers, websites, mobile applications
##
Text 2: OpenAI has trained cutting-edge language models that are very good at understanding and generating text. Our API provides access to these models and can be used to solve virtually any task that involves processing language.
Keywords 2: OpenAI, language models, text processing, API.
##
Text 3: {text}
Keywords 3:
✅微调:在此处查看微调最佳实践。
6. 减少“蓬松”和不精确的描述
不太有效的❌:
The description for this product should be fairly short, a few sentences only, and not too much more.
更好的✅:
Use a 3 to 5 sentence paragraph to describe this product.
7.与其说什么不该做,不如说什么该做
不太有效的❌:
The following is a conversation between an Agent and a Customer. DO NOT ASK USERNAME OR PASSWORD. DO NOT REPEAT.
Customer: I can’t log in to my account.
Agent:
更好的✅:
The following is a conversation between an Agent and a Customer. The agent will attempt to diagnose the problem and suggest a solution, whilst refraining from asking any questions related to PII. Instead of asking for PII, such as username or password, refer the user to the help article www.samplewebsite.com/help/faq
Customer: I can’t log in to my account.
Agent:
8. 特定于代码生成——使用“引导词”将模型推向特定模式
不太有效的❌:
# Write a simple python function that
# 1. Ask me for a number in mile
# 2. It converts miles to kilometers
在下面的代码示例中,向模型添加“ import ”提示它应该开始用 Python 编写。(类似地,“SELECT”是 SQL 语句开始的一个很好的提示。)
更好的✅:
# Write a simple python function that
# 1. Ask me for a number in mile
# 2. It converts miles to kilometers
import
参数
通常,我们发现model
和是改变模型输出的最常用参数。 temperature
-
model
–更高性能的模型更昂贵并且具有更高的延迟。 -
temperature
–衡量模型输出不太可能的标记的频率。越高temperature
,输出越随机(并且通常具有创造性)。然而,这与“真实”不同。对于大多数事实用例,例如数据提取和如实问答,temperature
0 是最好的。 -
max_tokens
( maximum length) – 不控制输出的长度,而是令牌生成的硬截止限制。理想情况下,您不会经常达到此限制,因为您的模型会在它认为完成时或达到您定义的停止序列时停止。 -
stop
(停止序列) – 一组字符(标记),在生成时会导致文本生成停止。
有关其他参数说明,请参阅API 参考。
其他资源
如果您对其他资源感兴趣,我们建议:
-
导游
-
OpenAI cookbook repo – 包含使用 API 完成常见任务的示例代码和提示,包括使用嵌入进行问答
原创文章,作者:校长,如若转载,请注明出处:https://www.yundongfang.com/Yun212310.html