
- DeepLearning.AI 에서 진행하는 ChatGPT Prompt Engineering for Developers 강의를 듣고 정리합니다.
- 모든 예시는 한국어로 답변하도록 수정되었습니다.
(응답시간이 길어집니다.)
개발자를 위한 프롬프트 엔지니어링이 필요한 이유는 다음과 같습니다.

기존의 Base LLM은 입력에 대해 비슷한 유형의 텍스트를 생성하는 반면, Instruction Tuned LLM은 RLHF(사람의 피드백을 통한 강화학습)을 통해 입력에 대한 답변을 생성합니다.
prompt를 통해 원하는 답변을 생성하도록 만들어졌기 때문에, prompt에 따라 답변이 달라질 수 있고, 중요성이 대두되는 것입니다.
💡Tips! 똑똑하지만 당신의 작업의 세부사항을 모르는 사람에게 일을 시킨다고 생각하고 prompt를 작성해보자.
강의에서 사용할 수 있는 api key와 jupyter notebook을 제공하므로, 실습과 함께 해보시기를 추천합니다. :O
"""```---<><tag></tag>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}```
"""
모델이 원하는 결과물을 만들기 위해서는 가능한 한 명확하고 구체적인 지시사항을 제공하여 모델이 원하는 결과물로 이끌어야 하며, 명확한 프롬프트와 짧은 프롬프트를 혼동하지 말고, 많은 경우 더 많은 명확성과 문맥을 제공하는 긴 프롬프트가 더 자세하고 관련성 높은 결과물을 이끌어낼 수 있다.
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.
"""
[
{
"book_id": 1,
"title": "불멸의 꽃",
"author": "김지영",
"genre": "판타지"
},
{
"book_id": 2,
"title": "그림자의 눈",
"author": "이현주",
"genre": "미스터리"
},
{
"book_id": 3,
"title": "바다의 노래",
"author": "박지은",
"genre": "로맨스"
}
]
프롬프트 개발은 반복 프로세싱이므로, 원하는 바를 적확히 수행할 수 있도록 반복적으로 수정 및 수행 과정이 필요하다.
아래의 제품정보(Product info)에 따라 마케팅에 사용할 문구를 요구하는 프롬프트이다. 해당 예시는 반복을 통해 어떻게 프롬프트를 개선할 수 있는 지 보여준다.
Product infofact_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 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}```
"""
이 의자는 다양한 색상과 베이스 마감 옵션으로 제공되며, 플라스틱 또는 패브릭/가죽으로 제작됩니다. 또한, 적당한 크기로 가정 및 비즈니스 환경에서 사용할 수 있습니다.
이러한 과정을 통해 해당 정보를 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 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}```
"""
미드 세기를 연상시키는 아름다운 가구 시리즈의 일부로, 서랍장, 책상, 책장, 회의용 테이블 등이 있습니다. 셸 색상과 베이스 마감 옵션이 여러 가지 있습니다. 플라스틱 등받이와 앞면 패브릭 (SWC-100) 또는 10가지 패브릭과 6가지 가죽 옵션으로 완전히 패브릭으로 된 SWC-110으로 사용할 수 있습니다. 베이스 마감 옵션은 스테인레스 스틸, 매트 블랙, 광택 화이트 또는 크롬입니다. 팔걸이가 있는 또는 없는 의자가 있습니다. 가정용 또는 비즈니스 환경에 적합하며 계약 사용을 위해 적격입니다.
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 폼
이탈리아