
Answer-first summary for fast verification
Answer: ```python prompt_template = "Tell me a {adjecive} joke" prompt = PromptTemplate( input_variables=["adjecive"], template=prompt_template ) llm = LLMChain(prompt=prompt) llm.generate("funny") ```
## Explanation Option A is correct because it properly uses the LLMChain with the PromptTemplate object and passes the input variable "funny" to the `generate()` method. This is the standard way to use LangChain's LLMChain: 1. **PromptTemplate** is created with input variables and template 2. **LLMChain** is initialized with the prompt template 3. **generate()** method is called with the input values for the template variables Option B is incorrect because: - It tries to format the prompt template before passing it to LLMChain (`prompt.format("funny")`) - This would result in a formatted string instead of a PromptTemplate object - The `generate()` method is then called without any arguments, but LLMChain expects input values In LangChain, the correct pattern is to pass the PromptTemplate object to LLMChain and then provide the input variables when calling generate() or invoke() methods.
Author: LeetQuiz .
Ultimate access to all questions.
Assuming the API key was properly defined, what change does the Generative AI Engineer need to make to fix their chain?
A
prompt_template = "Tell me a {adjecive} joke"
prompt = PromptTemplate(
input_variables=["adjecive"],
template=prompt_template
)
llm = LLMChain(prompt=prompt)
llm.generate("funny")
prompt_template = "Tell me a {adjecive} joke"
prompt = PromptTemplate(
input_variables=["adjecive"],
template=prompt_template
)
llm = LLMChain(prompt=prompt)
llm.generate("funny")
B
prompt_template = "Tell me a {adjecive} joke"
prompt = PromptTemplate(
input_variables=["adjecive"],
template=prompt_template
)
llm = LLMChain(prompt=prompt.format("funny"))
llm.generate()
prompt_template = "Tell me a {adjecive} joke"
prompt = PromptTemplate(
input_variables=["adjecive"],
template=prompt_template
)
llm = LLMChain(prompt=prompt.format("funny"))
llm.generate()
No comments yet.