어시스턴트 역할 활용하기

OpenAI API 활용하기

James Chapman

Curriculum Manager, DataCamp

단일 턴 작업을 위한 채팅 완성

response = client.chat.completions.create(
  model="gpt-4o-mini",
  messages=[{"role": "system",
             "content": "You are a data science tutor."},
            {"role": "user",
             "content": "What is the difference between mutable and immutable objects?"}]
)
  • System: 어시스턴트의 _동작_ 제어
  • User: 어시스턴트에 _지시_
  • Assistant: 사용자 지시에 대한 응답
OpenAI API 활용하기

예시 제공하기

  • 모델을 올바른 방향으로 유도
  • 어시스턴트 메시지를 제공하는 것은 샷 프롬프팅의 더 구조화된 형태
  • 예시: Python 프로그래밍 튜터
    • 사용자 질문 및 답변 예시

데이터 과학 올빼미.

OpenAI API 활용하기

예시 제공하기

response = client.chat.completions.create(
  model="gpt-4o-mini",
  messages=[{"role": "system",
             "content": "You are a Python programming tutor who speaks concisely."},

{"role": "user", "content": "How do you define a Python list?"},
{"role": "assistant", "content": "Lists are defined by enclosing a comma-separated sequence of objects inside square brackets [ ]."},
{"role": "user", "content": "What is the difference between mutable and immutable objects?"}] )
OpenAI API 활용하기

응답

print(response.choices[0].message.content)
Mutable objects can be changed after creation (e.g., lists, dictionaries). Immutable objects
cannot be altered once created (e.g., strings, tuples).
  • 예시 수 실험
OpenAI API 활용하기

System vs. assistant vs. user

System → 중요한 템플릿 서식

Output the information in this format:
name | age | occupation

Assistant → 예시 대화

User → 새 입력에 필요한 컨텍스트(단일 턴인 경우 많음)

Create a job advert for an AI Engineer. Use this job advert as a template:

Job Title: Data Engineer
...
OpenAI API 활용하기

연습해 봅시다!

OpenAI API 활용하기

Preparing Video For Download...