반복적 프롬프트 엔지니어링 및 개선

OpenAI API로 배우는 프롬프트 엔지니어링

Fouad Trad

Machine Learning Engineer

반복적 프롬프트 엔지니어링

  • 처음부터 완벽한 프롬프트는 없습니다
  • 프롬프트 엔지니어링은 반복적인 과정입니다
    • 프롬프트 작성
    • 모델에 입력
    • 출력 관찰 및 분석
    • 프롬프트 개선을 위해 반복

서로 연결된 네 개의 화살표가 있는 파란색 순환 이미지.

OpenAI API로 배우는 프롬프트 엔지니어링

프롬프트 개선

초기 프롬프트
prompt = "Generate an Excel sheet containing
five student names and their grades"

print(get_response(prompt))
I'm sorry, but as a text-based AI, I am 
unable to directly provide an Excel sheet. 
However, I can help you generate a sample
representation of the data you requested.
개선된 프롬프트
prompt = "Generate a table that I can copy 
to Excel, containing five student names and 
their grades"
print(get_response(prompt))
| Student Name | Grade |
|--------------|-------|
| Student 1    |  90   |
| Student 2    |  85   |
| Student 3    |  95   |
| Student 4    |  88   |
| Student 5    |  92   |
OpenAI API로 배우는 프롬프트 엔지니어링

예시: 파이썬 함수 분석

code = '''
def calculate_rectangle_area(length, width):
    area = length * width
    return area
'''

직사각형과 가로 및 세로를 이용한 넓이 계산 공식을 보여주는 이미지. Area = length\*width.

OpenAI API로 배우는 프롬프트 엔지니어링

예시: 초기 프롬프트

prompt = f"""
  Analyze the code delimited by triple backticks with one sentence
  ```{code}```.
"""
print(get_response(prompt))
The code calculates the area of a rectangle based on its length and width.
OpenAI API로 배우는 프롬프트 엔지니어링

예시: 프롬프트 개선

프로그래밍 언어를 얻기 위해 프롬프트를 수정합니다

prompt = f"""
  Analyze the code delimited by triple backticks and provide its programming 
  language with one sentence 
  ```{code}```.
"""
print(get_response(prompt))
The provided code is a function written in Python that calculates the area of a 
rectangle based on its length and width.
OpenAI API로 배우는 프롬프트 엔지니어링

예시: 프롬프트 개선

구조화된 출력을 얻기 위해 프롬프트를 수정합니다

prompt = f"""
  For the function delimited by triple backticks, provide in a structured format
  the following:
  - description: one sentence short description
  - language: the programming language used
  - input: the inputs to the function
  - output: the output returned by the function
  ```{code}```.
"""
print(get_response(prompt))
OpenAI API로 배우는 프롬프트 엔지니어링

예시: 프롬프트 개선

description: This function calculates the area of a rectangle.

language: Python

input:
 - length: The length of the rectangle.
 - width: The width of the rectangle.

output:
 - area: The calculated area of the rectangle, which is the product of the length 
 and width.
OpenAI API로 배우는 프롬프트 엔지니어링

퓨샷 프롬프트 개선

  • 날씨 설명 분류

초기 프롬프트

prompt = """
Clear skies and a gentle breeze. -> Sunny
Heavy rain and thunderstorms expected. -> Rainy
Fresh snowfall with freezing temperatures. -> 
"""
print(get_response(prompt))
Snowy
OpenAI API로 배우는 프롬프트 엔지니어링

퓨샷 프롬프트 개선

  • 날씨 설명 분류

초기 프롬프트

prompt = """
Clear skies and a gentle breeze. -> Sunny
Heavy rain and thunderstorms expected. -> Rainy
The wind of change brought a refreshing breeze to the company's operations. -> 
"""
print(get_response(prompt))
Windy
OpenAI API로 배우는 프롬프트 엔지니어링

퓨샷 프롬프트 개선

개선된 프롬프트

prompt = """
Clear skies and a gentle breeze. -> Sunny
Heavy rain and thunderstorms expected. -> Rainy
The political climate in the country was stormy -> Unknown
The wind of change brought a refreshing breeze to the company's operations. -> 
"""
print(get_response(prompt))
Unknown
OpenAI API로 배우는 프롬프트 엔지니어링

다양한 프롬프트 유형의 개선

  • 퓨샷 프롬프트: 예시 개선
  • 다단계 프롬프트: 안내 단계 개선
  • 사고 사슬 및 자기 일관성 프롬프트: 문제 설명 개선

세 줄의 토글과 이를 조정하는 손이 개선 과정을 나타내는 이미지.

OpenAI API로 배우는 프롬프트 엔지니어링

연습해 봅시다!

OpenAI API로 배우는 프롬프트 엔지니어링

Preparing Video For Download...