프롬프트 엔지니어링의 핵심 원칙

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

Fouad Trad

Machine Learning Engineer

명확하고 정확한 프롬프트

빵집과 집 사이의 두 경로를 보여주는 다이어그램. 하나는 단순하고 짧아 효과적이며, 다른 하나는 복잡하고 길어 비효과적임.

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

핵심 원칙

 

  • 🎬 적절한 동사 사용
  • 💬 구체적이고 정확한 지시
  • ❗ 잘 구조화된 구분자 프롬프트
OpenAI API로 배우는 프롬프트 엔지니어링

동사로 지시하기

  • 모델에 할 일을 지시

사용할 동사(쓰기, 완성하기, 설명하기, 묘사하기, 평가하기) 표.

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

모호한 동사 피하기

  • 모델의 이해를 혼란시킴

사용할 동사(쓰기, 완성하기, 설명하기, 묘사하기, 평가하기)와 피해야 할 동사(이해하다, 생각하다, 느끼다, 시도하다, 알다) 표.

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

동사를 활용한 효과적 프롬프트

prompt = "Think about the issue of 
deforestation."
response = get_response(prompt)
print(response)
Deforestation is a significant 
environmental issue involving 
permanently removing
or destroying forests and woodlands. 
It has far-reaching impacts on the 
environment, ecosystems, wildlife, 
and human communities. [...]
prompt = "Propose strategies to 
reduce deforestation."
response = get_response(prompt)
print(response)
Reducing deforestation requires 
a comprehensive and multi-dimensional 
approach involving various stakeholders. 
Here are several strategies 
that can help address the issue:
Strengthen Forest Governance
Promote Sustainable Land Use [...]
OpenAI API로 배우는 프롬프트 엔지니어링

상세 지시 구성하기

 

다음에 대해 구체적이고 명확하며 상세한 지시를 제공하세요:

  • 📖 맥락
  • 📏 출력 길이
  • 🖌 형식과 스타일
  • 👥👥 대상자
OpenAI API로 배우는 프롬프트 엔지니어링

지시를 포함한 효과적 프롬프트

비효과적 프롬프트: "개에 대해 말해줘."

효과적 프롬프트

prompt = "Write a descriptive paragraph about the behavior and characteristics of 
Golden Retrievers, highlighting their friendly nature, intelligence, 
and suitability as family pets."
print(get_response(prompt))
Golden Retrievers are beloved worldwide for their exceptional behavior, remarkable 
characteristics, and friendly nature. They are highly intelligent, trainable, and 
adaptable, making them great companions for families, including those with children.
OpenAI API로 배우는 프롬프트 엔지니어링

출력 길이 제한하기

max_tokens:

  • 토큰 수 제한
  • 출력이 이를 우회할 수 없음
  • 불완전하거나 잘린 응답 가능

프롬프트:

  • 단어·문장·문단 수 제한
  • 출력이 이를 우회할 수 있음
  • 완전한 응답 유도
OpenAI API로 배우는 프롬프트 엔지니어링

프롬프트 구성 요소

  • 지시와 처리할 입력 데이터
  • 예: 텍스트 요약
    • 지시: 주어진 텍스트 요약
    • 입력 데이터: 요약할 텍스트

텍스트 요약 작업을 나타내는 아이콘

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

구분자로 구조화된 프롬프트 작성

  • 지시로 프롬프트를 시작
  • 입력 부분을 지정하려면 구분자(괄호, 대괄호, 백틱 등) 사용
  • 사용한 구분자를 명시
prompt = """Summarize the text delimited by triple backticks into bullet points.
           ```TEXT GOES HERE```"""
response = get_response(prompt)
OpenAI API로 배우는 프롬프트 엔지니어링

포매팅 문자열(f-string) 사용

  • 정의된 문자열을 다른 문자열에 포함
text = "This is a sample text to summarize"

prompt = f"""Summarize the text delimited by triple backticks into bullet points. ```{text}```"""
print(prompt)
Summarize the text delimited by triple backticks into bullet points.
```This is a sample text to summarize```
OpenAI API로 배우는 프롬프트 엔지니어링

연습해 봅시다!

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

Preparing Video For Download...