ChatGPT Prompt Engineering for Developers - Iterative Prompt Development

Iterative Pompt Development

Prompt guidlines

  • Be clear and specific
  • Analyze why result does not give desired output
  • Refine the idea and the prompt
  • Repeat
复制代码
  import openai
  import os

  from dotenv import load_dotenv, find_dotenv
  _ = load_dotenv(find_dotenv()) # read local .env file

  openai.api_key  = os.getenv('OPENAI_API_KEY')

  def get_completion(prompt, model="gpt-3.5-turbo"):
      messages = [{"role": "user", "content": prompt}]
      response = openai.ChatCompletion.create(
          model=model,
          messages=messages,
          temperature=0, # this is the degree of randomness of
      )
      return response.choices[0].message["content"]

  fact_sheet_chair = """
  OVERVIEW
  - Part of a beautiful family of mid-century inspired office including filing cabinets, desks, bookcases, meeting tables,
  - 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 optio
  - 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 = 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)

  len(response.split(" "))

  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 3 sentences.
  # Use at most 280 characters.

  Technical specifications: ```{fact_sheet_chair}```
  """
  response = get_completion(prompt)
  print(response)

  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 = 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)

  from IPython. display import display, HTML
  display(HTML(respnse))

Iterative Process

  • Try somthing

  • Analyze where the result does not give what you want

  • Clarify instrictons, give more time to think

  • Refine prompts with a batch of examples

相关推荐
阿拉雷️10 分钟前
Prompt工程设计实践:从基础模板到场景化策略
人工智能·语言模型·prompt
dKjmLJLU31 天前
AI Prompt 工程化设计最佳实践(Harness Engineering)
人工智能·prompt
Augustzero2 天前
Codex Desktop 新建会话无法发送消息:一次由旧版 CLI 路径引发的故障排查
chatgpt·agent
风雨中的小七2 天前
解密Prompt系列70. 从 MLA 到 CSA,聊聊大模型 Attention 的“瘦身”与“闪送”
prompt
xn71333 天前
ChatGPT 生图如何自动导入 Astro 内容站:base64 桥接、frontmatter 更新和封面校验
chatgpt
gptAI_plus4 天前
用 React + TypeScript 写一个世界杯淘汰赛对阵树组件
chatgpt·openai
AI工程效率栈8 天前
AI 帮你补异常处理时,新人最容易犯的错:把失败悄悄变成成功
gpt·chatgpt
凌奕11 天前
让你的 AI 编程助手「偷懒」:50k Star 的 Ponytail,让 Agent 少写一半代码
chatgpt·agent·claude
星落zx17 天前
Spring Boot 多模型集成:优雅调用全球主流大模型
人工智能·spring boot·chatgpt
在路上走着走着17 天前
Prompt Engineering 入门指南:从原理到上手
人工智能·prompt