การใช้งาน assistant role

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

James Chapman

AI Curriculum Lead, DataCamp

งานแบบ single-turn

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?"}]
)
  • System: ควบคุม พฤติกรรม ของ assistant
  • User: สั่งงาน assistant
  • Assistant: ตอบสนองต่อคำสั่งของ user
การใช้งาน DeepSeek ใน Python

การให้ตัวอย่าง

 

  • ช่วยนำทางโมเดลให้ตอบได้ถูกทิศทาง
  • การใส่ assistant messages เป็นรูปแบบที่มีโครงสร้างของ shot-prompting
  • ตัวอย่าง: Python Programming Tutor
    • ตัวอย่างคำถามและคำตอบของ user

นกฮูกด้านวิทยาศาสตร์ข้อมูล

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

การให้ตัวอย่าง

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": "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?"}] )
การใช้งาน DeepSeek ใน Python

ผลลัพธ์ที่ได้

print(response.choices[0].message.content)
Mutable objects can be changed after creation (like lists), while immutable objects cannot
(like tuples or strings).
  • ทดลอง ปรับจำนวนตัวอย่าง
การใช้งาน DeepSeek ใน Python

System vs. assistant vs. user

System → กำหนดรูปแบบ template ที่สำคัญ

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

Assistant → ตัวอย่างบทสนทนา

User → บริบทสำหรับ input ใหม่ (มักเป็น single-turn)

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

Job Title: Data Engineer
...
การใช้งาน DeepSeek ใน Python

มาฝึกกันเถอะ!

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

Preparing Video For Download...