運用 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:控制助理的「行為」
  • User:用來「指示」助理
  • 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...