目录
- 一、说明
- 二、安装环境
- 三、Iterative
- 第一次写Prompt
- 第二次写Prompt
- 第三次写Prompt
- 第四次写Prompt
- 第五次写Prompt
- 四、总结
一、说明
这是吴恩达 《ChatGPT Prompt Engineering for Developers》 的课程笔记系列。
本文是第三讲的内容:Iterative
课程主讲:Andrew Ng,Isa Fulford
Isa Fulford也是《OpenAI Cookbook》的主要贡献者之一
二、安装环境
参考: ChatGPT提示词工程(一):Guidelines准则 的第二节
三、Iterative
在本课中,您将反复分析和提炼您的提示,以根据产品情况说明书生成营销文案
第一次写Prompt
例子:
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 = 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 = 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)
添加了最多50个单次的条件,运行结果:
第三次写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.
Use at most 50 words.
Technical specifications: ```{fact_sheet_chair}```
"""
response = get_completion(prompt)
print(response)
运行结果:
第四次写Prompt
添加一些ID的说明,再次改写:
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)
第五次写Prompt
要求以表格的形式展示一些材料等数据,并且输出为html格式:
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)
将输出的html渲染出来的效果:
from IPython.display import display, HTML
display(HTML(response))
https://blog.csdn.net/Jay_Xio/article/details/130452393
四、总结
编写Prompt时,您对要做什么、要完成的任务有一个想法,然后您可以第一次尝试编写一个Prompt,希望它是明确和具体的,如果合适的话,可能会给系统时间思考,然后您可以运行它,看看您会得到什么结果。
如果它第一次不能很好地工作,那么迭代过程就是找出为什么指令不够清楚,或者为什么它没有给算法足够的时间来思考,允许您完善想法,完善提示,等等。
并多次循环这个循环,直到得到一个适用于您的应用程序的Prompt
https://blog.csdn.net/Jay_Xio/article/details/130452393