编写更有效的提示
Azure OpenAI 模型能够以惊人的准确度生成对自然语言查询的响应。 但是,响应的质量在很大程度上取决于提示的写入程度。 开发人员可以通过在其提示中使用不同技术来优化 Azure OpenAI 模型的性能,从而生成更准确、更相关的响应。
提供清晰说明
明确询问 Azure OpenAI 模型所需的内容是获取所需结果的一种方法。 通过尽可能的描述,模型可以生成最符合所需内容的响应。
例如,假设你想要为新的水瓶创建产品说明。 请考虑与每个提示关联的答案:
提示
Write a product description for a new water bottle
响应
Introducing the latest addition to our product line - the innovative and eco-friendly water bottle.
Made from high-quality, BPA-free materials, this bottle is designed to keep your beverages at the
perfect temperature for hours. Its sleek and stylish design makes it the perfect accessory for any
outdoor activity or workout session. With its convenient carrying handle and leak-proof lid, you
can take it with you wherever you go, without worrying about spills or leaks. Plus, its easy-to-clean
design ensures that you can use it again and again, making it the perfect choice for anyone looking
for a reliable and sustainable water bottle.
与类似的提示相比,具有清晰说明。
提示
Write a product description for a new water bottle that is 100% recycled. Be sure to include that
it comes in natural colors with no dyes, and each purchase removes 10 pounds of plastic from our
oceans
响应
Introducing our newest water bottle, the eco-friendly choice for the conscious consumer. Made from
100% recycled materials and available in natural colors with no dyes, this bottle is not only
stylish but also sustainable. Each purchase of this bottle removes 10 pounds of plastic from
our oceans, making it a responsible choice for those who care about the environment. Its durable
and leak-proof design makes it perfect for outdoor activities, while its easy-to-carry handle
makes it convenient to take on the go. Join us in our mission to reduce plastic waste and choose
this eco-friendly water bottle for your daily hydration needs.
包括需要包含的详细信息可让模型知道要添加到说明中的信息,使其对新产品的描述更加准确。
可以推断此方法包含复杂的说明,例如要包括的详细信息的项目符号列表、响应的长度或要包含在输出中的所需格式。 尝试确切地询问想要在结果中看到的内容,你可能会对模型满足请求的效果感到惊讶。
说明的格式
如何设置说明的格式可能会影响模型解释提示的方式。 近度偏差可能会影响模型,其中位于提示末尾的信息对输出的影响比对开头的信息的影响更大。 通过重复提示末尾的说明和评估对生成的响应的影响,可以获得更好的响应。
在聊天方案中使用 ChatCompletion
时,这种近度偏差也会起作用,其中提示中包含的对话中较新的消息对响应的影响更大。 下一个单元更深入地介绍如何使用对话来提高响应质量,但将重要信息放在提示的末尾附近可能会获得更好的响应。
使用节标记
设置说明格式的特定技术是拆分提示开头或末尾的说明,并在 ---
或 ###
块中包含用户内容。 这些标记使模型能够更清楚地区分说明和内容。 例如:
Translate the text into French
---
What's the weather going to be like today?
---
注意
分区标记的最佳做法可能会随着将来的版本而更改。
主要内容、支持内容和基础内容
包括用于响应的模型的内容,使模型能够更准确地回答。 可以通过两种方式来考虑此内容:主要内容和支持内容。
主要内容是指作为查询主题的内容,例如要翻译的句子或要汇总的文章。 此内容通常包含在提示的开头或末尾(作为说明,并按 ---
块进行区分),其中包含介绍如何使用它的说明。
例如,假设我们有一篇要总结的长文章。 我们可以将其放在提示符的 ---
块中,然后以说明结尾。
---
<insert full article here, as primary content>
---
Summarize this article and identify three takeaways in a bulleted list
支持内容是可能会改变响应的内容,但不是提示的焦点或主题。 支持内容的示例包括名称、首选项、响应中要包含的未来日期等。 提供支持内容可让模型做出更完整、更准确的响应,并且更有可能包含所需信息。
例如,鉴于促销电子邮件非常长,模型能够提取关键信息。 如果随后在提示中添加支持内容,并指定要查找的特定内容,则模型可以提供更有用的响应。 在这种情况下,电子邮件是主要内容,并将你感兴趣的具体内容作为支持内容
---
<insert full email here, as primary content>
---
<the next line is the supporting content>
Topics I'm very interested in: AI, webinar dates, submission deadlines
Extract the key points from the above email, and put them in a bulleted list:
基础内容通过为要从中提取答案的模型提供内容,使模型能够提供可靠的答案。 基础内容可以是询问相关问题的论文或文章、公司常见问题解答文档或比训练模型所基于的数据更新的信息。 如果需要更可靠且最新的响应,或者需要引用未发布的或特定信息,强烈建议使用基础内容。
基础内容与主要内容不同,因为它是用于回答提示查询的信息源,而不是针对摘要或翻译等操作的内容。 例如,当提供关于 AI 历史的未发表研究论文时,它可以使用该基础内容回答问题。
---
<insert unpublished paper on the history of AI here, as grounding content>
---
Where and when did the field of AI start?
此基础数据使模型能够给出更准确、更明智的答案,这些答案可能不是训练的数据集的一部分。
提示
提示是模型构建的前导字,通常有助于朝着正确方向塑造响应。 它们通常与说明一起使用,但并不总是如此。 提示模型进行代码生成时,提示特别有用。 当前的 Azure OpenAI 模型可以生成一些有趣的代码片段,但未来模块中将更深入地介绍代码生成。
例如,如果需要帮助创建 SQL 查询,请提供所需内容的说明以及查询的开头:
Write a join query to get customer names with purchases in the past 30 days between tables named orders and customer on customer ID.
SELECT
模型响应从提示中断的位置开始,在 SQL 中继续,即使我们从未要求过特定语言。 其他示例可能是通过提供有关所需应用的代码注释,并在提示末尾将 import
添加为前导字,或者以所需语言提供类似内容来帮助 Python 代码。
另一个示例,鉴于提示中有大量客户评论,结尾为:
Summarize the reviews above:
Most common complaints:
-
模型随后知道根据评论中提供的上下文完成语句。