承接上篇,继续整理关于面向开发者的Prompt Engineering教程笔记,教程的Introduction和Guidelines for Prompting部分见:如何使用ChatGPT得到更满意的结果:Prompt Engineering (2)_Dorothy30的博客-CSDN博客
整理的内容基本上英文原文都来自于教程,有需要的朋友可以直接戳https://learn.deeplearning.ai/。这篇笔记主要整理教程中lterative Prompt Development的部分
目录
当在使用大型语言模型构建应用程序时,可能在很少第一次尝试时就得到了最终应用程序中使用的prompt。但这没关系,只要你有一个良好的迭代过程来不断改进prompt,那么在最后你就可以找到适合你要实现的任务的有效prompt。
迭代开发的流程如下图所示:
编写prompt时遵循的流程:
- 清晰明确地写prompt
- 分析为什么不能得到期望的输出
- 根据分析的结果改进你的想法以及对应的prompt
- 重复进行以上步骤
ps: 在这里吴恩达老师提到,由于一个好的prompt是需要迭代开发的,所以他个人对那些声称有30个完美提示的互联网文章没有太在意,因为他认为可能并不存在一个适用于所有情况的完美的prompt。
下面给出tutorial里面展示的例子,即从产品说明书中生成市场营销产品描述。
实例:产品说明书
fact_sheet_chair = """
OVERVIEW
- Part of a beautiful family of mid-century inspired office furniture,
including filing cabinets, desks, bookcases, meeting tables, and more.
- Several options of shell color and base finishes.
- Available with plastic back and front upholstery (SWC-100)
or full upholstery (SWC-110) in 10 fabric and 6 leather options.
- Base finish options are: stainless steel, matte black,
gloss white, or chrome.
- Chair is available with or without armrests.
- Suitable for home or business settings.
- Qualified for contract use.
CONSTRUCTION
- 5-wheel plastic coated aluminum base.
- Pneumatic chair adjust for easy raise/lower action.
DIMENSIONS
- WIDTH 53 CM | 20.87”
- DEPTH 51 CM | 20.08”
- HEIGHT 80 CM | 31.50”
- SEAT HEIGHT 44 CM | 17.32”
- SEAT DEPTH 41 CM | 16.14”
OPTIONS
- Soft or hard-floor caster options.
- Two choices of seat foam densities:
medium (1.8 lb/ft3) or high (2.8 lb/ft3)
- Armless or 8 position PU armrests
MATERIALS
SHELL BASE GLIDER
- Cast Aluminum with modified nylon PA6/PA66 coating.
- Shell thickness: 10 mm.
SEAT
- HD36 foam
COUNTRY OF ORIGIN
- Italy
"""
最初使用的Prompt
prompt = f"""
Your task is to help a marketing team create a
description for a retail website of a product based
on a technical fact sheet.
Write a product description based on the information
provided in the technical specifications delimited by
triple backticks.
Technical specifications: ```{fact_sheet_chair}```
"""
response = get_completion(prompt)
print(response)
在运行这个prompt过后,得到的结果可能并不能令你满意。这时候需要分析为什么你的prompt不能得到你期望的输出,并逐一解决改进prompt。在教程中主要解决了三个问题。
问题1:文本太长
如果上述返回的prompt太长,可以在更新的prompt里面添加一行“Use at most 50 words”
prompt = f"""
Your task is to help a marketing team create a
description for a retail website of a product based
on a technical fact sheet.
Write a product description based on the information
provided in the technical specifications delimited by
triple backticks.
**Use at most 50 words.**
Technical specifications: ```{fact_sheet_chair}```
"""
response = get_completion(prompt)
print(response)
问题2:文本关注了错误的细节
如果prompt生成的市场营销描述针对的是顾客,但是想要生成的是针对家居零销商的描述,那么你需要在prompt里面添加对于受众的说明。
prompt = f"""
Your task is to help a marketing team create a
description for a retail website of a product based
on a technical fact sheet.
Write a product description based on the information
provided in the technical specifications delimited by
triple backticks.
**The description is intended for furniture retailers,
so should be technical in nature and focus on the
materials the product is constructed from.**
At the end of the description, include every 7-character
Product ID in the technical specification.
Use at most 50 words.
Technical specifications: ```{fact_sheet_chair}```
"""
response = get_completion(prompt)
print(response)
问题3:需要用一个表格来描述结果
如果你需要输出为表格来更清晰的展示结果,那么可以进一步完善prompt,加上你对输出结果的期望格式。
prompt = f"""
Your task is to help a marketing team create a
description for a retail website of a product based
on a technical fact sheet.
Write a product description based on the information
provided in the technical specifications delimited by
triple backticks.
The description is intended for furniture retailers,
so should be technical in nature and focus on the
materials the product is constructed from.
At the end of the description, include every 7-character
Product ID in the technical specification.
After the description, include a table that gives the
product's dimensions. The table should have two columns.
In the first column include the name of the dimension.
In the second column include the measurements in inches only.
Give the table the title 'Product Dimensions'.
Format everything as HTML that can be used in a website.
Place the description in a <div> element.
Technical specifications: ```{fact_sheet_chair}```
"""
response = get_completion(prompt)
print(response)