使用 assistant 角色

在 Python 中使用 DeepSeek

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:控制 assistant 的行为
  • User:对 assistant 下达指令
  • Assistant:根据指令作答
在 Python 中使用 DeepSeek

提供示例

 

  • 引导模型走对方向
  • 提供 assistant 消息是更结构化的示例提示方式
  • 示例:Python 编程导师
    • 示例用户问答

一只数据科学猫头鹰。

在 Python 中使用 DeepSeek

提供示例

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?"}] )
在 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、assistant、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

让我们一起练习吧!

在 Python 中使用 DeepSeek

Preparing Video For Download...