0
0
LangChainframework~10 mins

Why LangChain simplifies LLM application development - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a LangChain LLM instance.

LangChain
from langchain.llms import OpenAI
llm = OpenAI(model_name=[1])
Drag options to blanks, or click blank then click option'
A"text-davinci-003"
B"gpt-3.5-turbo"
C"bert-base"
D"gpt-2"
Attempts:
3 left
💡 Hint
Common Mistakes
Using unsupported model names like 'bert-base' which is not an OpenAI model.
2fill in blank
medium

Complete the code to generate a response from the LLM.

LangChain
response = llm.[1]("Hello, how are you?")
Drag options to blanks, or click blank then click option'
Acall
Bgenerate_text
Crun
Dpredict
Attempts:
3 left
💡 Hint
Common Mistakes
Using methods like 'generate_text' which do not exist in LangChain's LLM interface.
3fill in blank
hard

Fix the error in the code to create a prompt template.

LangChain
from langchain.prompts import PromptTemplate
prompt = PromptTemplate(input_variables=[[1]], template="Hello, {{name}}!")
Drag options to blanks, or click blank then click option'
Aname
B"name"
C["name"]
D'name'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a single string without list brackets, causing type errors.
4fill in blank
hard

Fill both blanks to create and use a chain that combines prompt and LLM.

LangChain
from langchain.chains import LLMChain
chain = LLMChain(llm=[1], prompt=[2])
result = chain.run("LangChain")
Drag options to blanks, or click blank then click option'
Allm
Bprompt
Cllm_chain
Dchain
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names that are not defined or incorrect parameter names.
5fill in blank
hard

Fill all three blanks to create a simple LangChain app that uses an LLM, prompt, and chain.

LangChain
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"))
Drag options to blanks, or click blank then click option'
A"text-davinci-003"
B["name"]
Cllm
D"gpt-4"
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect model names, wrong input_variables format, or wrong variable names in the chain.