リトリーバル用プロンプトの作成
RAG を実装するうえで重要なのが、リトリーバル用のプロンプトです。この演習では、リトリーバルチェーン向けのチャットプロンプトテンプレートを作成し、提供されたコンテキストだけを使って LLM が回答できるかを確認します。
すでに使用可能な llm が定義されています。
この演習はコースの一部です
LangChain で学ぶ Retrieval Augmented Generation (RAG)
演習の手順
- 文字列
promptを再利用可能なチャットプロンプトテンプレートに変換します。 - 提供された
llmとプロンプトテンプレートを統合する LCEL チェーンを作成します。 - 提供された入力で
chainを実行し、モデルが与えられたコンテキストのみを使って回答できるか確認します。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
prompt = """
Use the only the context provided to answer the following question. If you don't know the answer, reply that you are unsure.
Context: {context}
Question: {question}
"""
# Convert the string into a chat prompt template
prompt_template = ____
# Create an LCEL chain to test the prompt
chain = ____ | ____
# Invoke the chain on the inputs provided
print(chain.____({"context": "DataCamp's RAG course was created by Meri Nova and James Chapman!", "question": "Who created DataCamp's RAG course?"}))