เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

การเพิ่ม Guardrail

หนึ่งในการใช้งาน system message ที่ได้รับความนิยมมากที่สุดคือการเพิ่ม guardrail ซึ่งเป็นการกำหนดข้อจำกัดให้กับผลลัพธ์ของโมเดล

ในแบบฝึกหัดนี้ จะกำหนดข้อจำกัดให้โมเดลปฏิเสธการสร้างแผนการเรียนรู้ที่ ไม่ เกี่ยวข้องกับภาษา เนื่องจากระบบกำลังมุ่งเน้นเฉพาะด้านนั้น พร้อมทั้งออกแบบข้อความสำหรับผู้ใช้ที่ขอแผนการเรียนรู้ประเภทดังกล่าว เพื่อให้เข้าใจถึงการเปลี่ยนแปลงนี้

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

การใช้งาน DeepSeek ใน Python

ดูคอร์ส

คำแนะนำการฝึกหัด

  • เขียน chat request ให้สมบูรณ์ โดยส่ง system message ใน sys_msg จากนั้นทดสอบด้วย user message ที่มีทักษะที่ไม่เกี่ยวข้องกับภาษา เช่น การเล่นสเก็ต

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

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)
แก้ไขและรันโค้ด