当前位置:   article > 正文

吴恩达prompt 笔记2:迭代提示开发(Iterative Prompt Develelopment)

吴恩达prompt 笔记2:迭代提示开发(Iterative Prompt Develelopment)

1 前言 

  • 我们很难在初次尝试中就设计出最佳的提示,因此需要根据ChatGPT的反馈进行分析,分析输出具体在哪里不符合期望,然后不断思考和优化提示。
  • 如果有条件的话,最好是利用批量的样本来改善提示,这样可以对你的优化结果有一个较为直观的体现。

准备代码和之前的一样,就不加注释了,详情见: 大模型笔记:吴恩达 ChatGPT Prompt Engineering for Developers(1) prompt的基本原则和策略-CSDN博客

  1. import openai
  2. import os
  3. from dotenv import load_dotenv, find_dotenv
  4. _ = load_dotenv(find_dotenv()) # read local .env file
  5. openai.api_key = os.getenv('OPENAI_API_KEY')
  6. def get_completion(prompt, model="gpt-3.5-turbo"):
  7. messages = [{"role": "user", "content": prompt}]
  8. response = openai.ChatCompletion.create(
  9. model=model,
  10. messages=messages,
  11. temperature=0, # this is the degree of randomness of the model's output
  12. )
  13. return response.choices[0].message["content"]

2 举例:根据货物单,生成一个货品描述

2.0 货物单:

  1. fact_sheet_chair = """
  2. OVERVIEW
  3. - Part of a beautiful family of mid-century inspired office furniture,
  4. including filing cabinets, desks, bookcases, meeting tables, and more.
  5. - Several options of shell color and base finishes.
  6. - Available with plastic back and front upholstery (SWC-100)
  7. or full upholstery (SWC-110) in 10 fabric and 6 leather options.
  8. - Base finish options are: stainless steel, matte black,
  9. gloss white, or chrome.
  10. - Chair is available with or without armrests.
  11. - Suitable for home or business settings.
  12. - Qualified for contract use.
  13. CONSTRUCTION
  14. - 5-wheel plastic coated aluminum base.
  15. - Pneumatic chair adjust for easy raise/lower action.
  16. DIMENSIONS
  17. - WIDTH 53 CM | 20.87”
  18. - DEPTH 51 CM | 20.08”
  19. - HEIGHT 80 CM | 31.50”
  20. - SEAT HEIGHT 44 CM | 17.32”
  21. - SEAT DEPTH 41 CM | 16.14”
  22. OPTIONS
  23. - Soft or hard-floor caster options.
  24. - Two choices of seat foam densities:
  25. medium (1.8 lb/ft3) or high (2.8 lb/ft3)
  26. - Armless or 8 position PU armrests
  27. MATERIALS
  28. SHELL BASE GLIDER
  29. - Cast Aluminum with modified nylon PA6/PA66 coating.
  30. - Shell thickness: 10 mm.
  31. SEAT
  32. - HD36 foam
  33. COUNTRY OF ORIGIN
  34. - Italy
  35. """

2.1 prompt 版本1

  1. prompt = f"""
  2. Your task is to help a marketing team create a
  3. description for a retail website of a product based
  4. on a technical fact sheet.
  5. Write a product description based on the information
  6. provided in the technical specifications delimited by
  7. triple backticks.
  8. Technical specifications: ```{fact_sheet_chair}```
  9. """
  10. response = get_completion(prompt)
  11. print(response)
  12. '''
  13. Introducing the SWC-100/SWC-110 Office Chair, a sleek and stylish addition to any workspace. This chair is part of a stunning collection of mid-century inspired office furniture, offering a cohesive look with filing cabinets, desks, bookcases, meeting tables, and more.
  14. Customize your chair with several options for shell color and base finishes to suit your personal style. Choose between plastic back and front upholstery or full upholstery in a variety of fabric and leather options. The base finish options include stainless steel, matte black, gloss white, or chrome, allowing you to create the perfect look for your space.
  15. Designed for both home and business settings, this chair is suitable for contract use and offers comfort and functionality. The 5-wheel plastic coated aluminum base provides stability, while the pneumatic chair adjust allows for easy raise/lower action.
  16. With dimensions of 53 cm in width, 51 cm in depth, and 80 cm in height, this chair offers a comfortable seat height of 44 cm and seat depth of 41 cm. Choose between soft or hard-floor caster options and two seat foam densities for personalized comfort. The chair is available with or without armrests, with the option for 8 position PU armrests.
  17. Constructed with high-quality materials, including a cast aluminum shell with modified nylon coating and HD36 foam seat, this chair is both durable and stylish. Made in Italy, you can trust in the craftsmanship and design of this office chair.
  18. Elevate your workspace with the SWC-100/SWC-110 Office Chair, a versatile and sophisticated seating solution for any environment.
  19. '''

2.2 prompt 版本2:限制 生成文本的长度

+ Use at most 50 words.

  1. prompt = f"""
  2. Your task is to help a marketing team create a
  3. description for a retail website of a product based
  4. on a technical fact sheet.
  5. Write a product description based on the information
  6. provided in the technical specifications delimited by
  7. triple backticks.
  8. Use at most 50 words.
  9. Technical specifications: ```{fact_sheet_chair}```
  10. """
  11. response = get_completion(prompt)
  12. print(response)
  13. '''
  14. Introducing our versatile and stylish office chair, part of a
  15. mid-century inspired furniture collection. Available in various
  16. colors and finishes, with customizable upholstery options.
  17. Designed for comfort and durability, suitable for both home
  18. and business use. Made in Italy with high-quality materials.
  19. Elevate your workspace with this modern chair.
  20. '''
  21. len(response.split()) #49

2.3 prompt 版本3:着重在听众需要的信息上

+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.

  1. prompt = f"""
  2. Your task is to help a marketing team create a
  3. description for a retail website of a product based
  4. on a technical fact sheet.
  5. Write a product description based on the information
  6. provided in the technical specifications delimited by
  7. triple backticks.
  8. The description is intended for furniture retailers,
  9. so should be technical in nature and focus on the
  10. materials the product is constructed from.
  11. At the end of the description, include every 7-character
  12. Product ID in the technical specification.
  13. Use at most 50 words.
  14. Technical specifications: ```{fact_sheet_chair}```
  15. """
  16. response = get_completion(prompt)
  17. print(response)
  18. '''
  19. Introducing our versatile office chair, part of a stylish mid-century
  20. inspired collection. Choose from a variety of shell colors and base
  21. finishes to suit your space. Constructed with a durable aluminum base
  22. and high-density foam seat for comfort. Perfect for home or office use.
  23. Product IDs: SWC-100, SWC-110.
  24. '''

2.4 prompt 版本4:添加产品各维度数据的表格

+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'.

  1. prompt = f"""
  2. Your task is to help a marketing team create a
  3. description for a retail website of a product based
  4. on a technical fact sheet.
  5. Write a product description based on the information
  6. provided in the technical specifications delimited by
  7. triple backticks.
  8. The description is intended for furniture retailers,
  9. so should be technical in nature and focus on the
  10. materials the product is constructed from.
  11. At the end of the description, include every 7-character
  12. Product ID in the technical specification.
  13. After the description, include a table that gives the
  14. product's dimensions. The table should have two columns.
  15. In the first column include the name of the dimension.
  16. In the second column include the measurements in inches only.
  17. Give the table the title 'Product Dimensions'.
  18. Use at most 50 words.
  19. Technical specifications: ```{fact_sheet_chair}```
  20. """
  21. response = get_completion(prompt)
  22. print(response)
  23. '''
  24. Introducing our versatile and stylish office chair, part of a
  25. mid-century inspired furniture collection. Constructed with a
  26. durable cast aluminum shell and base glider coated with modified
  27. nylon. The seat features high-density foam for comfort. Available
  28. in various colors and finishes. Perfect for home or office use.
  29. Product IDs: SWC-100, SWC-110
  30. Product Dimensions:
  31. | Dimension | Measurement |
  32. |--------------|-------------|
  33. | Width | 20.87" |
  34. | Depth | 20.08" |
  35. | Height | 31.50" |
  36. | Seat Height | 17.32" |
  37. | Seat Depth | 16.14" |
  38. Shop now and elevate your workspace with this Italian-made chair.
  39. '''

2.5 prompt 版本5:输出内容改成HTML格式

+Format everything as HTML that can be used in a website.  Place the description in a <div> element.

  1. prompt = f"""
  2. Your task is to help a marketing team create a
  3. description for a retail website of a product based
  4. on a technical fact sheet.
  5. Write a product description based on the information
  6. provided in the technical specifications delimited by
  7. triple backticks.
  8. The description is intended for furniture retailers,
  9. so should be technical in nature and focus on the
  10. materials the product is constructed from.
  11. At the end of the description, include every 7-character
  12. Product ID in the technical specification.
  13. After the description, include a table that gives the
  14. product's dimensions. The table should have two columns.
  15. In the first column include the name of the dimension.
  16. In the second column include the measurements in inches only.
  17. Give the table the title 'Product Dimensions'.
  18. Format everything as HTML that can be used in a website.
  19. Place the description in a <div> element.
  20. Technical specifications: ```{fact_sheet_chair}```
  21. """
  22. response = get_completion(prompt)
  23. print(response)
  24. '''
  25. <div>
  26. <p>This mid-century inspired office chair is a stylish and functional
  27. addition to any workspace. The chair is available in a variety of shell
  28. colors and base finishes to suit your aesthetic preferences. You can
  29. choose between plastic back and front upholstery or full upholstery in
  30. a range of fabric and leather options. The chair is constructed with a
  31. durable 5-wheel plastic coated aluminum base and features a pneumatic
  32. adjust for easy height customization. Whether you need a chair for your
  33. home office or a business setting, this chair is a versatile and comfortable
  34. choice. Made in Italy, this chair is designed for both style and durability.</p>
  35. <p>Product IDs: SWC-100, SWC-110</p>
  36. <table>
  37. <caption>Product Dimensions</caption>
  38. <tr>
  39. <th>Dimension</th>
  40. <th>Measurements (inches)</th>
  41. </tr>
  42. <tr>
  43. <td>Width</td>
  44. <td>20.87"</td>
  45. </tr>
  46. <tr>
  47. <td>Depth</td>
  48. <td>20.08"</td>
  49. </tr>
  50. <tr>
  51. <td>Height</td>
  52. <td>31.50"</td>
  53. </tr>
  54. <tr>
  55. <td>Seat Height</td>
  56. <td>17.32"</td>
  57. </tr>
  58. <tr>
  59. <td>Seat Depth</td>
  60. <td>16.14"</td>
  61. </tr>
  62. </table>
  63. </div>
  64. '''

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/244246
推荐阅读
相关标签
  

闽ICP备14008679号