サンプル会話でコンテキストを与える
MyPersonalDelivery という、さまざまな品目に幅広く対応する配送サービスがあるとします。お客様のあらゆるニーズをサポートするカスタマーサポート用チャットボットを作成したいと考えています。そのために、過去の会話から、会社が配送する品目に関する context_question と context_answer を提供し、新しいユーザーからのプロンプトでモデルがこのコンテキストを認識できるかをテストします。
OpenAI パッケージ、context_question と context_answer の文字列はあらかじめ読み込まれています。
この演習はコースの一部です
OpenAI API で学ぶプロンプトエンジニアリング
演習の手順
- チャットボットの目的を定義し、やさしい口調で問い合わせに答えるよう促す
system_promptを作成します。 system_prompt、context_question、context_answerを使って、チャットボットが新しいユーザーからの問い合わせに回答する際のコンテキストとして利用できる会話を構成します。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
client = OpenAI(api_key="")
# Define the system prompt
system_prompt = "____"
context_question = "What types of items can be delivered using MyPersonalDelivery?"
context_answer = "We deliver everything from everyday essentials such as groceries, medications, and documents to larger items like electronics, clothing, and furniture. However, please note that we currently do not offer delivery for hazardous materials or extremely fragile items requiring special handling."
# Add the context to the model
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "____", "content": ____},
{"role": "____", "content": ____},
{"role": "____", "content": ____ },
{"role": "user", "content": "Do you deliver furniture?"}])
response = response.choices[0].message.content
print(response)