Sử dụng vai trò assistant

Làm việc với DeepSeek bằng Python

James Chapman

Curriculum Manager, DataCamp

Nhiệm vụ một lượt

response = client.chat.completions.create(
  model="deepseek-ai/DeepSeek-V3",
  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: điều khiển hành vi của assistant
  • User: chỉ dẫn assistant
  • Assistant: phản hồi theo chỉ dẫn của user
Làm việc với DeepSeek bằng Python

Cung cấp ví dụ

 

  • Hướng mô hình đi đúng hướng
  • Cung cấp tin nhắn assistant là dạng shot-prompting có cấu trúc hơn
  • Ví dụ: Gia sư Lập trình Python
    • Câu hỏi và trả lời mẫu của người dùng

Một con cú khoa học dữ liệu.

Làm việc với DeepSeek bằng Python

Cung cấp ví dụ

response = client.chat.completions.create(
  model="deepseek-ai/DeepSeek-V3",
  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?"}] )
Làm việc với DeepSeek bằng Python

Phản hồi

print(response.choices[0].message.content)
Mutable objects can be changed after creation (like lists), while immutable objects cannot
(like tuples or strings).
  • Thử nghiệm số lượng ví dụ
Làm việc với DeepSeek bằng Python

System vs. assistant vs. user

System → định dạng mẫu quan trọng

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

Assistant → hội thoại mẫu

User → ngữ cảnh cần cho đầu vào mới (thường một lượt)

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

Job Title: Data Engineer
...
Làm việc với DeepSeek bằng Python

Ayo berlatih!

Làm việc với DeepSeek bằng Python

Preparing Video For Download...