フューショットプロンプトテンプレートの構築
例が構造化された形式になったので、フューショットプロンプトテンプレートを作成しましょう!質問と回答のペアを次の形式に変換するテンプレートを作成します:
Question: Example question
Example Answer
この演習を完了するために必要なLangChainのクラスはすべて事前に読み込まれています。
この演習はコースの一部です
LangChainを使ったLLMアプリケーション開発
演習の手順
- 回答のフォーマットに
questionキーとanswerキーを含めるよう、プロンプトを完成させます。 FewShotPromptTemplateを使って、examplesとexample_promptを含む少数ショットのプロンプトを作成します。- 提供された接尾辞に基づいて入力変数のリストを完成させる。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# Complete the prompt for formatting answers
example_prompt = PromptTemplate.from_template("Question: {____}\n{____}")
# Create the few-shot prompt
prompt_template = ____(
examples=____,
example_prompt=____,
suffix="Question: {input}",
input_variables=["____"],
)
prompt = prompt_template.invoke({"input": "What is Jack's favorite technology on DataCamp?"})
print(prompt.text)