การใช้บทบาท assistant

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

James Chapman

AI Curriculum Lead, DataCamp

งานแบบเทิร์นเดียว

response = client.chat.completions.create(
  model="deepseek-ai/DeepSeek-V4.1-Flash",
  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: ควบคุมพฤติกรรมของผู้ช่วย
  • User: สั่งการผู้ช่วย
  • Assistant: คำตอบต่อคำสั่งของผู้ใช้
การใช้งาน DeepSeek ใน Python

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

 

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

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

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

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

response = client.chat.completions.create(
  model="deepseek-ai/DeepSeek-V4.1-Flash",
  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 → การจัดรูปแบบเทมเพลตที่สำคัญ

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
...
การใช้งาน DeepSeek ใน Python

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

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

Preparing Video For Download...