Complete the code to create a LangChain LLM instance.
from langchain.llms import OpenAI llm = OpenAI(model_name=[1])
The OpenAI class in LangChain uses model names like text-davinci-003 to specify which LLM to use.
Complete the code to generate a response from the LLM.
response = llm.[1]("Hello, how are you?")
In LangChain, the predict method is used to get the LLM's response to a prompt.
Fix the error in the code to create a prompt template.
from langchain.prompts import PromptTemplate prompt = PromptTemplate(input_variables=[[1]], template="Hello, {{name}}!")
The input_variables parameter expects a list of strings, so it must be ["name"].
Fill both blanks to create and use a chain that combines prompt and LLM.
from langchain.chains import LLMChain chain = LLMChain(llm=[1], prompt=[2]) result = chain.run("LangChain")
The LLMChain constructor requires the llm and prompt arguments to connect the model and prompt template.
Fill all three blanks to create a simple LangChain app that uses an LLM, prompt, and chain.
from langchain.llms import OpenAI from langchain.prompts import PromptTemplate from langchain.chains import LLMChain llm = OpenAI(model_name=[1]) prompt = PromptTemplate(input_variables=[2], template="Say hello to {{name}}.") chain = LLMChain(llm=[3], prompt=prompt) print(chain.run("Alice"))
This code sets up an OpenAI LLM with model text-davinci-003, defines a prompt template with input variable name, and creates a chain connecting the LLM and prompt. Then it runs the chain with input Alice.