외부 컨텍스트 통합

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

Fouad Trad

Machine Learning Engineer

외부 컨텍스트의 필요성

  • 사전 학습된 언어 모델은 학습된 정보만 인식
  • 추가 컨텍스트 제공 필요
  • 정확성 및 효과 향상

모바일 기기의 챗봇을 나타내는 아이콘.

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

LLM의 정보 부족

  • 지식 기준 시점
system_prompt = "Act as a financial expert that knows about the latest trends."

user_prompt = "What are the top financial trends in 2023?"

print(get_response(system_prompt, user_prompt))
I apologize for any inconvenience, but as of my last knowledge update in 
September 2021, I don't have information about financial trends in 2023.
OpenAI API로 배우는 프롬프트 엔지니어링

LLM의 정보 부족

  • 비공개 정보 요청
system_prompt = "Act as a study buddy that helps me with my studies to succeed 
in exams."

user_prompt = "What is the name of my favorite instructor?" print(get_response(system_prompt, user_prompt))
I don't have personal information about you, including the name of your 
favorite instructor.
OpenAI API로 배우는 프롬프트 엔지니어링

추가 정보를 제공하는 방법

  • 이전 대화 샘플
  • 시스템 프롬프트

대화 측면을 나타내는 두 개의 메시지 대화 상자 아이콘.

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

샘플 대화

  • 특정 질문에 답하도록 모델 유도
response = client.chat.completions.create(
  model="gpt-4o-mini",
  messages=[{"role": "system",
             "content": "You are a customer service chatbot that responds to user queries in a gentle way"},

{"role": "user", "content": "What services do you offer?"},
{"role": "assistant", "content": "We provide services for web application development, mobile app development, and custom software solutions."},
{"role": "user", "content": "How many services do you have?"}])
print(response.choices[0].message.content)
We have 3 services including web application development, mobile app development, and custom software solutions.
  • 단점: 많은 샘플이 필요할 수 있음
OpenAI API로 배우는 프롬프트 엔지니어링

시스템 프롬프트

  • 챗봇 응답에 필요한 컨텍스트 포함
services = "ABC Tech Solutions, a leading IT company, offers a range of services: 
application development, mobile app development, and custom software solutions."

system_prompt = f"""You are a customer service chatbot that responds to user queries in a gentle way. Some information about our services are delimited by triple backticks. ```{services}```"""
user_prompt = "How many services do you offer?" print(get_response(system_prompt, user_prompt))
We have 3 services including web application development, mobile app development, 
and custom software solutions.
OpenAI API로 배우는 프롬프트 엔지니어링

마지막 참고 사항

  • 앞의 방법들은 소규모 컨텍스트에 적합
  • 대규모 컨텍스트에는 더 정교한 기법 필요

경고를 나타내는 아이콘.

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

연습해 봅시다!

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

Preparing Video For Download...