始める無料で始める

プロンプトテンプレートとチェーン

この演習では、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": ____}))
コードを編集して実行