外部コンテキストの組み込み

OpenAI API で学ぶプロンプトエンジニアリング

Fouad Trad

Machine Learning Engineer

外部コンテキストの必要性

  • 事前学習済みモデルは学習済み情報のみ認識する
  • より多くのコンテキストの提供が必要
  • 精度と効果の向上

スマートフォン上のチャットボットを表すアイコン。

OpenAI API で学ぶプロンプトエンジニアリング

LLMの情報不足

  • 知識のカットオフ
system_prompt = "Act as a financial expert that knows about the latest trends."

user_prompt = "What are the top financial trends in 2023?"

print(get_response(system_prompt, user_prompt))
I apologize for any inconvenience, but as of my last knowledge update in 
September 2021, I don't have information about financial trends in 2023.
OpenAI API で学ぶプロンプトエンジニアリング

LLMの情報不足

  • 非公開情報の要求
system_prompt = "Act as a study buddy that helps me with my studies to succeed 
in exams."

user_prompt = "What is the name of my favorite instructor?" print(get_response(system_prompt, user_prompt))
I don't have personal information about you, including the name of your 
favorite instructor.
OpenAI API で学ぶプロンプトエンジニアリング

追加情報の提供方法

  • 会話サンプルの活用
  • システムプロンプトの活用

会話を表す2つのメッセージダイアログボックスのアイコン。

OpenAI API で学ぶプロンプトエンジニアリング

会話サンプル

  • 特定の質問に答えるようモデルを誘導する
response = client.chat.completions.create(
  model="gpt-4o-mini",
  messages=[{"role": "system",
             "content": "You are a customer service chatbot that responds to user queries in a gentle way"},

{"role": "user", "content": "What services do you offer?"},
{"role": "assistant", "content": "We provide services for web application development, mobile app development, and custom software solutions."},
{"role": "user", "content": "How many services do you have?"}])
print(response.choices[0].message.content)
We have 3 services including web application development, mobile app development, and custom software solutions.
  • デメリット:多数のサンプルが必要になる場合がある
OpenAI API で学ぶプロンプトエンジニアリング

システムプロンプト

  • チャットボットの回答に必要なコンテキストを含める
services = "ABC Tech Solutions, a leading IT company, offers a range of services: 
application development, mobile app development, and custom software solutions."

system_prompt = f"""You are a customer service chatbot that responds to user queries in a gentle way. Some information about our services are delimited by triple backticks. ```{services}```"""
user_prompt = "How many services do you offer?" print(get_response(system_prompt, user_prompt))
We have 3 services including web application development, mobile app development, 
and custom software solutions.
OpenAI API で学ぶプロンプトエンジニアリング

最後に

  • 前述の方法は小規模なコンテキストに有効
  • 大規模なコンテキストにはより高度な手法が必要

警告を表すアイコン。

OpenAI API で学ぶプロンプトエンジニアリング

練習しましょう!

OpenAI API で学ぶプロンプトエンジニアリング

Preparing Video For Download...