プロンプトテンプレートとチェーン
この演習では、LangChain の中核コンポーネントである プロンプトテンプレート と チェーン を使い始めます!
ChatOpenAI を含む、この演習に必要なクラスはすでに読み込まれています。
この演習はコースの一部です
LangChain で開発する LLM アプリケーション
演習の手順
- 用意された
templateテキストを、標準(チャットではない)プロンプトテンプレートに変換します。 - プロンプトテンプレートを LLM に渡すチェーンを作成します。
- 与えられた
question変数でチェーンを実行します。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# Create a prompt template from the template string
template = "You are an artificial intelligence assistant, answer the question. {question}"
prompt = PromptTemplate.____(
template=____
)
llm = ChatOpenAI(model="gpt-4o-mini", api_key='')
# Create a chain to integrate the prompt template and LLM
llm_chain = ____ | ____
# Invoke the chain on the question
question = "How does LangChain make LLM application development easier?"
print(llm_chain.invoke({"question": ____}))