アシスタントロールの活用

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 を使いこなす

例を示す

 

  • モデルを正しい方向に導く
  • アシスタントメッセージの提供は、より構造化されたショットプロンプティングの一種です
  • 例: 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...