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

OpenAI APIを使いこなす

James Chapman

Curriculum Manager, DataCamp

シングルターンタスク向けChat Completion

response = client.chat.completions.create(
  model="gpt-4o-mini",
  messages=[{"role": "system",
             "content": "You are a data science tutor."},
            {"role": "user",
             "content": "What is the difference between mutable and immutable objects?"}]
)
  • システム:アシスタントの振る舞い制御
  • ユーザー:アシスタントへの_指示_に使用
  • アシスタント:ユーザーの指示への応答に使用
OpenAI APIを使いこなす

例の提示

  • 意図する出力に近づける
  • アシスタントメッセージの提供:より整理されたフューショットプロンプティング
  • : Python学習チューター
    • ユーザーの質問と回答の例

データサイエンスのフクロウ。

OpenAI APIを使いこなす

例の提示

response = client.chat.completions.create(
  model="gpt-4o-mini",
  messages=[{"role": "system",
             "content": "You are a Python programming tutor who speaks concisely."},

{"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?"}] )
OpenAI APIを使いこなす

レスポンス

print(response.choices[0].message.content)
Mutable objects can be changed after creation (e.g., lists, dictionaries). Immutable objects
cannot be altered once created (e.g., strings, tuples).
  • 提示する例の数:何度か試行してみる
OpenAI APIを使いこなす

システム・アシスタント・ユーザーの違い

システム → 重要なフォーマット指定

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

アシスタント → 会話例

ユーザー → 新しい質問に必要な文脈(シングルターンに多い)

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

Job Title: Data Engineer
...
OpenAI APIを使いこなす

練習しましょう!

OpenAI APIを使いこなす

Preparing Video For Download...