시작하기무료로 시작하기

가드레일 추가하기

시스템 메시지의 가장 일반적인 쓰임새 중 하나는 모델 출력에 제한을 두는 가드레일(guardrails)을 추가하는 것입니다.

이번 연습에서는 언어와 관련되지 않은 학습 계획을 생성하지 못하도록 제한을 둘 거예요. 이 시스템이 해당 분야에 특화되고 있기 때문이죠. 또한 이런 유형의 학습 계획을 요청하는 사용자에게 변경 사항을 이해할 수 있도록 맞춤 메시지도 설계하세요.

이 연습은 강의의 일부입니다

Python으로 DeepSeek 활용하기

강의 보기

연습 안내

  • 채팅 요청을 완성하고, sys_msg에 시스템 메시지를 제공하세요. 그리고 롤러스케이팅처럼 언어와 관련되지 않은 기술을 포함한 사용자 메시지로 테스트하세요.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

client = OpenAI(api_key="", base_url="https://api.together.xyz/v1")

sys_msg = """You are a study planning assistant that creates plans for learning new skills, returning only the structured plan.

If these skills are non related to languages, return only the message:

'Apologies, to focus on languages, we no longer create learning plans on other topics.'
"""

# Create a request to the chat model
response = client.chat.completions.create(
  model="deepseek-ai/DeepSeek-V4-Pro",
  messages=[
    {"role": "____", "content": ____},
    {"role": "user", "content": "Help me learn to ____."}
  ]
)

print(response.choices[0].message.content)
코드 편집 및 실행