03 Iterative
本节主要通过代码来讲解如何在迭代中找到合适的prompt。对于初学者来说,第一次使用Prompt不一定得到语气的结果,开发者可以采用下述流程进行迭代优化:
- 给出清晰、具体的指令
- 如果结果不正确,分析原因
- 调整prompt
- 重复上述过程直至得到想要的结果
1) 示例
比如你想要模型为某产品的零售网站写一段描述,给出的指令为
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}```
"""
其中fact_sheet_chair
为网站的技术说明书。
- Issue1: 如果模型给出的结果特别长。这时你可以在指令中增加
Use at most 50 words
或者Use at most 3 sentences
或者Use at most 200 characters
来限制输出的长度。模型给出了52个token的句子,效果还可以。 - Issue2: 如果此时内容对技术细节表述不够精确,这时你可以增加
The description is intended for furniture retailers, so should be technical in nature and focus on the materials the product is constructed from.
令内容聚焦于特定内容。 - Issue3: 你希望模型增加一些维度的信息,此时你可以增加
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.
指定模型给出其他需要的信息并结构化输出HTML。你可以通过display(HTML(response))
将html转化为table。
最终你得到的结构化表格为