生成AIエンジニアが、以下のコードを使用してLangChainでシンプルなプロンプトテンプレートをテストしていますが、エラーが発生しています。 Python from langchain.chains import LLMChain from langchain_community.llms import OpenAI from langchain_core.prompts import PromptTemplate prompt_template = "{形容詞}のジョークを教えてください" prompt = PromptTemplate(input_variables=["adjective"], template=prompt_template) # ... (エラーが発生しやすいセクション) APIキーが正しく定義されていると仮定した場合、生成AIエンジニアはチェーンを修正するためにどのような変更を行う必要がありますか?
正解:C
The error in the original snippet usually stems from the improper instantiation of the LLMChain or the incorrect call to the .generate() method. In LangChain, an LLMChain requires two primary components: an LLM (the engine) and a Prompt (the template). Option C provides the correct syntax: first, the PromptTemplate is defined with the correct input_variables. Second, the OpenAI model is instantiated. Third, the LLMChain binds the model and the prompt together. Finally, the .generate() method expects a list of dictionaries, where each dictionary represents a set of inputs for the prompt variables. Options A, B, and D in the original image contain syntax errors such as passing the variable directly into the chain initialization or missing the dictionary list format required by the standard LangChain API for batch-like generation.