채팅 역할과 시스템 메시지

Python으로 DeepSeek 활용하기

James Chapman

AI Curriculum Lead, DataCamp

단일 턴에서 다중 턴으로

 

단일 턴 작업

  • 텍스트 생성
  • 텍스트 변환
  • 분류

하나의 프롬프트와 하나의 응답으로 구성된 단일 턴 작업.

Python으로 DeepSeek 활용하기

단일 턴에서 다중 턴으로

 

단일 턴 작업

  • 텍스트 생성
  • 텍스트 변환
  • 분류

 

다중 턴 대화

→ 이전 프롬프트와 응답을 기반으로 구성

여러 프롬프트와 응답으로 구성된 다중 턴 작업.

Python으로 DeepSeek 활용하기

역할

 

  • 시스템: 어시스턴트의 _동작_ 제어
  • 사용자: 어시스턴트에게 _지시_
  • 어시스턴트: 사용자 지시에 대한 _응답_
    • 개발자가 예시 제공을 위해 직접 작성 가능

채팅 상호작용의 세 가지 역할: 시스템, 사용자, 어시스턴트.

Python으로 DeepSeek 활용하기

요청 설정

response = client.chat.completions.create(
    model="deepseek-ai/DeepSeek-V4-Pro",
    messages=[{"role": "user", "content": prompt}]
)
Python으로 DeepSeek 활용하기

프롬프트 설정

messages=[{"role": "system",
           "content": "You are a Python programming tutor who responds using concise,
                         one-sentence explanations."},
          {"role": "user",
           "content": "What is the difference between mutable and immutable objects?"}]
Python으로 DeepSeek 활용하기

요청 실행

response = client.chat.completions.create(
  model="deepseek-ai/DeepSeek-V4-Pro",
  messages=[{"role": "system",
             "content": "You are a Python programming tutor who responds using concise,
                         one-sentence explanations."},
            {"role": "user",
             "content": "What is the difference between mutable and immutable objects?"}]
)

print(response.choices[0].message.content)
Mutable objects can be changed after creation (like lists), while immutable objects
cannot be modified once created (like tuples or strings).
Python으로 DeepSeek 활용하기

오용 방지

 

  • 시스템 메시지: 가이드라인{{2}} 포함 가능
    • 모델 출력 제한

도로 옆 가드레일.

금융 튜터 챗봇과 금융 어드바이저 챗봇.

Python으로 DeepSeek 활용하기

시스템 메시지로 오용 방지

sys_msg = """
You are finance education assistant that helps students study for exams.

If you are asked for specific, real-world financial advice with risk to their
finances, respond with only:

I'm sorry, I am not allowed to provide financial advice.
"""
Python으로 DeepSeek 활용하기

시스템 메시지로 오용 방지

response = client.chat.completions.create(
  model="deepseek-ai/DeepSeek-V4-Pro",
  messages=[{"role": "system",
             "content": sys_msg},
            {"role": "user",
             "content": "Which stocks should I invest in?"}]
)

print(response.choices[0].message.content)
I'm sorry, I am not allowed to provide financial advice.
Python으로 DeepSeek 활용하기

연습해 봅시다!

Python으로 DeepSeek 활용하기

Preparing Video For Download...