Complete the code to import the core LangChain class for building chains.
from langchain.chains import [1]
The LLMChain class is the core chain class that connects prompts with language models in LangChain.
Complete the code to create a prompt template with a variable placeholder.
from langchain.prompts import PromptTemplate prompt = PromptTemplate(template="Hello, {name}!", input_variables=["[1]"])
The placeholder in the template must match the variable name in input_variables. Here, it is name.
Fix the error in creating an LLMChain by filling the missing argument.
from langchain.llms import OpenAI from langchain.chains import LLMChain llm = OpenAI() chain = LLMChain(llm=llm, prompt=[1])
The LLMChain expects a prompt argument which is an instance of PromptTemplate. The variable holding the prompt is usually named prompt.
Fill both blanks to create a simple memory-enabled chain that remembers previous inputs.
from langchain.memory import [1] memory = [2]() chain = LLMChain(llm=llm, prompt=prompt, memory=memory)
The ConversationBufferMemory class stores the conversation history in a buffer. It is imported and instantiated to enable memory in the chain.
Fill all three blanks to create a chain that uses an OpenAI LLM, a prompt template, and conversation memory.
from langchain.llms import [1] from langchain.prompts import [2] from langchain.memory import [3] llm = [1]() prompt = [2](template="Say hello to {name}", input_variables=["name"]) memory = [3]() chain = LLMChain(llm=llm, prompt=prompt, memory=memory)
This code imports and creates instances of OpenAI for the language model, PromptTemplate for the prompt, and ConversationBufferMemory for memory. These are combined in an LLMChain.