逐次的なチェーン用プロンプトの構築
次のいくつかの演習では、新しいスキルを学ぶ人をサポートするシステムを構築します。このシステムは、学習者が自分の好みや制約に合わせてプランを調整できるよう、段階的に構築する必要があります。LangChain の LCEL を活用して逐次チェーンを組み立てていきますが、最初のステップはこのシステムで使用するプロンプトテンプレートの設計です。
この演習はコースの一部です
LangChainを使ったLLMアプリケーション開発
演習の手順
- 入力として
learning_promptを受け取り、学習プランを作成するプロンプトテンプレート"activity"を作成しましょう。 - 入力として
time_promptを受け取り、プランを1週間以内に収まるよう調整するプロンプトテンプレート"learning_plan"を作成しましょう。 - 好きなアクティビティを指定して
learning_promptを呼び出しましょう(アイデアが思い浮かばない場合は"play golf"を試してみてください)。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# Create a prompt template that takes an input activity
learning_prompt = PromptTemplate(
input_variables=["____"],
template="I want to learn how to {activity}. Can you suggest how I can learn this step-by-step?"
)
# Create a prompt template that places a time constraint on the output
time_prompt = PromptTemplate(
____,
template="I only have one week. Can you create a plan to help me hit this goal: {learning_plan}."
)
# Invoke the learning_prompt with an activity
print(learning_prompt.____({"activity": "____"}))