使用 assistant 角色

在 Python 中使用 DeepSeek

James Chapman

AI Curriculum Lead, DataCamp

单轮任务

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:控制助手的行为
  • User:向助手下达指令
  • Assistant:对用户指令的回复
在 Python 中使用 DeepSeek

提供示例

 

  • 引导模型到正确方向
  • 提供 assistant 消息是更结构化的 few-shot 提示
  • 示例:Python 编程导师
    • 示例用户问答

一只数据科学猫头鹰。

在 Python 中使用 DeepSeek

提供示例

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?"}] )
在 Python 中使用 DeepSeek

回复

print(response.choices[0].message.content)
Mutable objects can be changed after creation (like lists), while immutable objects cannot
(like tuples or strings).
  • 试验示例数量
在 Python 中使用 DeepSeek

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
...
在 Python 中使用 DeepSeek

Passons à la pratique !

在 Python 中使用 DeepSeek

Preparing Video For Download...