Complete the code to create a simple chain that calls a language model.
from langchain.chains import [1] from langchain.llms import OpenAI llm = OpenAI() chain = [1](llm=llm) result = chain.run("Hello!")
The LLMChain class is used to create a chain that connects a language model to inputs and outputs.
Complete the code to import the base class for chains in LangChain.
from langchain.chains import [1]
The base class for chains in LangChain is called Chain.
Fix the error in the code to create a chain that uses a prompt template.
from langchain.chains import LLMChain from langchain.llms import OpenAI from langchain.prompts import [1] llm = OpenAI() prompt = [1](template="Say hello to {name}.") chain = LLMChain(llm=llm, prompt=prompt) result = chain.run(name="Alice")
The correct class to create prompt templates is PromptTemplate.
Fill both blanks to create a chain that uses a prompt template and runs with input.
from langchain.chains import [1] from langchain.prompts import [2] chain = [1](llm=llm, prompt=[2](template="Hello, {user}!") ) result = chain.run(user="Bob")
Use LLMChain to create the chain and PromptTemplate for the prompt.
Fill all three blanks to create a chain that uses a prompt template, runs with input, and prints the result.
from langchain.chains import [1] from langchain.prompts import [2] from langchain.llms import OpenAI llm = OpenAI() prompt = [2](template="Good morning, {name}!") chain = [1](llm=llm, prompt=prompt) result = chain.run(name="Eve") print(result)
The chain is created with LLMChain, the prompt with PromptTemplate, and the chain variable is named chain.