프롬프트 엔지니어링 소개

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

Fouad Trad

Machine Learning Engineer

프롬프트 엔지니어링이란?

원하는 응답을 얻기 위해 LLM에 제공하는 프롬프트 또는 지시를 설계하는 것

프롬프트 엔지니어링의 용어를 소개하는 엔지니어 그림.

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

프롬프트 엔지니어링은 레시피 작성과 같습니다

요리사가 음식을 만드는 이미지.

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

왜 프롬프트 엔지니어링인가?

  고품질 프롬프트가 고품질 답변으로 이어짐을 보여주는 시각 다이어그램

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

왜 프롬프트 엔지니어링인가?

  입력 프롬프트 품질이 답변 품질에 미치는 영향을 보여주는 시각 다이어그램. 고품질 프롬프트는 고품질 답변을, 저품질 프롬프트는 저품질 답변을 유발함.

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

복습: OpenAI API

  • OpenAI 모델과 상호작용 가능
  • 이 과정에서 이미 설정됨
  • Chat Completions 엔드포인트 접근

chatgpt_logo_white.png

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

복습: 메시지 역할

모든 메시지에는 세 가지 역할 중 하나가 있습니다

사용자 역할 아이콘을 나타내는 이미지.

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

복습: 메시지 역할

모든 메시지에는 세 가지 역할 중 하나가 있습니다

사용자와 어시스턴트 두 역할의 아이콘을 나타내는 이미지.

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

복습: 메시지 역할

모든 메시지에는 세 가지 역할 중 하나가 있습니다

사용자, 시스템, 어시스턴트 세 역할 각각의 아이콘을 나타내는 이미지

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

복습: 메시지 역할

모든 메시지에는 세 가지 역할 중 하나가 있습니다

세 역할의 아이콘과 시스템이 어시스턴트에게 메시지를 전달하는 화살표를 나타내는 이미지.

  • 시스템 메시지: 모델 동작을 안내함
OpenAI API로 배우는 프롬프트 엔지니어링

복습: 메시지 역할

모든 메시지에는 세 가지 역할 중 하나가 있습니다

세 역할의 아이콘과 시스템→어시스턴트, 사용자→어시스턴트 간 통신 화살표를 나타내는 이미지.

  • 시스템 메시지: 모델 동작을 안내함
  • 사용자 메시지: 사용자의 프롬프트
OpenAI API로 배우는 프롬프트 엔지니어링

복습: 메시지 역할

모든 메시지에는 세 가지 역할 중 하나가 있습니다

세 역할의 아이콘과 시스템→어시스턴트, 사용자→어시스턴트, 어시스턴트→사용자 간 통신 화살표를 나타내는 이미지.

  • 시스템 메시지: 모델 동작을 안내함
  • 사용자 메시지: 사용자의 프롬프트
  • 어시스턴트 메시지: 사용자 프롬프트에 대한 응답
OpenAI API로 배우는 프롬프트 엔지니어링

복습: 제어 파라미터

0에서 2 사이의 값을 나타내는 온도계 아이콘 이미지. 0은 무작위성 없음, 2는 최고 무작위성을 나타냄.

  • temperature: 응답의 무작위성 조절
OpenAI API로 배우는 프롬프트 엔지니어링

복습: 제어 파라미터

온도계 아이콘과 슬라이더 아이콘을 나타내는 이미지. 슬라이더의 낮은 값은 짧은 응답을 의미함.

  • temperature: 응답의 무작위성 조절
  • max_tokens: 응답 길이 조절
OpenAI API로 배우는 프롬프트 엔지니어링

복습: OpenAI API와의 통신

prompt = "What is prompt engineering?"

client = OpenAI(api_key="api_key")
response = client.chat.completions.create(
model = "gpt-4o-mini",
messages = [{"role": "user", "content": prompt}],
temperature = 0 )
print(response.choices[0].message.content)
Prompt engineering refers to the process of designing and refining prompts or 
instructions given to a language model like ChatGPT in order to elicit desired 
responses or behaviors. It involves formulating specific guidelines or hints to 
guide the model's output towards a desired outcome.
OpenAI API로 배우는 프롬프트 엔지니어링

get_response() 함수 만들기

def get_response(prompt):

response = client.chat.completions.create( model = "gpt-4o-mini", messages = [{"role": "user", "content": prompt}], temperature = 0 )
return response.choices[0].message.content

사용법

response = get_response("What is prompt engineering?")
print(response)
Prompt engineering refers to the process of designing and refining prompts or instructions given to a language model 
like ChatGPT in order to elicit desired responses or behaviors. It involves formulating specific guidelines or hints 
to guide the model's output towards a desired outcome.
OpenAI API로 배우는 프롬프트 엔지니어링

프롬프트 개선

prompt = "What is prompt engineering? Explain it in terms that can be understood 
by a 5-year-old"
response = get_response(prompt)
print(response)
Imagine you have a very smart friend who can understand and answer lots of 
questions. But sometimes, they might not understand exactly what you want or give 
the wrong answer. So, prompt engineering is like giving your friend really clear 
instructions or hints to help them give you the best answer possible.
OpenAI API로 배우는 프롬프트 엔지니어링

연습해 봅시다!

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

Preparing Video For Download...