[Prompt Engineering] ChatGPT Prompt Engineering for Developers

김예신·2023년 6월 4일

PromptEngineering

목록 보기
1/1
post-thumbnail

Intro

개발자를 위한 프롬프트 엔지니어링이 필요한 이유는 다음과 같습니다.

  • 인터넷에서 흔히 볼 수 있는 prompt는 대부분 특정하고 단발적인 작업을 웹 사용자 인터페이스를 위한 것입니다.
  • 하지만 개발자도구로써 LLMs를 API로 활용하면 원하는 소프트웨어 애플리케이션을 더 빠르게 만드는 데 도움울 줄 수 있습니다.


기존의 Base LLM은 입력에 대해 비슷한 유형의 텍스트를 생성하는 반면, Instruction Tuned LLM은 RLHF(사람의 피드백을 통한 강화학습)을 통해 입력에 대한 답변을 생성합니다.

prompt를 통해 원하는 답변을 생성하도록 만들어졌기 때문에, prompt에 따라 답변이 달라질 수 있고, 중요성이 대두되는 것입니다.

💡Tips! 똑똑하지만 당신의 작업의 세부사항을 모르는 사람에게 일을 시킨다고 생각하고 prompt를 작성해보자.


Guidelines

강의에서 사용할 수 있는 api key와 jupyter notebook을 제공하므로, 실습과 함께 해보시기를 추천합니다. :O

Prompting Principles

  • Principle 1: 명확하고 구체적인 지침을 작성하세요
    • clear != short
  • Principle 2: 모델에게 "생각"할 시간을 주세요

Tactics

Tactic 1: 구분 기호를 사용하여 입력의 구분되는 부분을 명확하게 표시합니다.

  • Examples
    • Triple quotes: """
    • Triple backticks: ```
    • Triple dashes: ---
    • Angle brackets: <>
    • XML tags: <tag></tag>

prompt example

text = f"""
You should express what you want a model to do by \ 
providing instructions that are as clear and \ 
specific as you can possibly make them. \ 
This will guide the model towards the desired output, \ 
and reduce the chances of receiving irrelevant \ 
or incorrect responses. Don't confuse writing a \ 
clear prompt with writing a short prompt. \ 
In many cases, longer prompts provide more clarity \ 
and context for the model, which can lead to \ 
more detailed and relevant outputs.
"""
prompt = f"""
Summarize the text delimited by triple backticks \ 
into a single sentence in Korean.
```{text}```
"""

output

모델이 원하는 결과물을 만들기 위해서는 가능한 한 명확하고 구체적인 지시사항을 제공하여 모델이 원하는 결과물로 이끌어야 하며, 명확한 프롬프트와 짧은 프롬프트를 혼동하지 말고, 많은 경우 더 많은 명확성과 문맥을 제공하는 긴 프롬프트가 더 자세하고 관련성 높은 결과물을 이끌어낼 수 있다.

Tatic 2: 구조화된 출력을 요청합니다.

prompt example

prompt = f"""
Generate a list of three made-up book titles along \ 
with their authors and genres in Korean. 
Provide them in JSON format with the following keys: 
book_id, title, author, genre.
"""

output

[
  {
    "book_id": 1,
    "title": "불멸의 꽃",
    "author": "김지영",
    "genre": "판타지"
  },
  {
    "book_id": 2,
    "title": "그림자의 눈",
    "author": "이현주",
    "genre": "미스터리"
  },
  {
    "book_id": 3,
    "title": "바다의 노래",
    "author": "박지은",
    "genre": "로맨스"
  }
]

Iterative

프롬프트 개발은 반복 프로세싱이므로, 원하는 바를 적확히 수행할 수 있도록 반복적으로 수정 및 수행 과정이 필요하다.

아래의 제품정보(Product info)에 따라 마케팅에 사용할 문구를 요구하는 프롬프트이다. 해당 예시는 반복을 통해 어떻게 프롬프트를 개선할 수 있는 지 보여준다.

Product info
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

Write Korean description

prompt example

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 Korean product description based on the information 
provided in the technical specifications delimited by 
triple backticks.

Technical specifications: ```{fact_sheet_chair}```
"""
# (output생략) 해당 프롬프트는 긴 설명글을 생성합니다.

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 in Korean based on the information 
provided in the technical specifications delimited by 
triple backticks.

Use at most 2 sentences.	# 짧게 만들기 위해 해당 지침을 추가함

Technical specifications: ```{fact_sheet_chair}```
"""

output

이 의자는 다양한 색상과 베이스 마감 옵션으로 제공되며, 플라스틱 또는 패브릭/가죽으로 제작됩니다. 또한, 적당한 크기로 가정 및 비즈니스 환경에서 사용할 수 있습니다.

Write description HTML

이러한 과정을 통해 해당 정보를 HTML로 요구합니다.
해당 프롬프트는 다음과 같습니다.

prompt example

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 in Korean 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}```
"""

output

Result of HTML... 더 보기

제품 설명

미드 세기를 연상시키는 아름다운 가구 시리즈의 일부로, 서랍장, 책상, 책장, 회의용 테이블 등이 있습니다. 셸 색상과 베이스 마감 옵션이 여러 가지 있습니다. 플라스틱 등받이와 앞면 패브릭 (SWC-100) 또는 10가지 패브릭과 6가지 가죽 옵션으로 완전히 패브릭으로 된 SWC-110으로 사용할 수 있습니다. 베이스 마감 옵션은 스테인레스 스틸, 매트 블랙, 광택 화이트 또는 크롬입니다. 팔걸이가 있는 또는 없는 의자가 있습니다. 가정용 또는 비즈니스 환경에 적합하며 계약 사용을 위해 적격입니다.

제품 ID

SWC-100, SWC-110

제품 크기

너비 53cm | 20.87인치
깊이 51cm | 20.08인치
높이 80cm | 31.50인치
좌석 높이 44cm | 17.32인치
좌석 깊이 41cm | 16.14인치

옵션

소프트 또는 하드 바닥 캐스터 옵션, 중간 (1.8 lb/ft3) 또는 높은 (2.8 lb/ft3) 밀도의 좌석 폼, 팔걸이 없는 또는 8단계 PU 팔걸이

소재

셸 베이스 글라이더 - 수정 나일론 PA6/PA66 코팅이 된 캐스트 알루미늄, 셸 두께: 10mm, 좌석 - HD36 폼

원산지

이탈리아

반복 과정

  • 시도한다.
  • 원하는 결과가 나오지 않은 부분을 분석한다.
  • 더 명확한 지시를 주어 모델에게 생각할 시간을 더 준다.
  • 몇개의 예시를 통해, 프롬프트를 정교화한다.
profile
life is dancing

0개의 댓글