0
0
LangChainframework~10 mins

What is a chain in LangChain - Interactive Quiz & Practice

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

Complete the code to create a simple chain that calls a language model.

LangChain
from langchain.chains import [1]
from langchain.llms import OpenAI

llm = OpenAI()
chain = [1](llm=llm)
result = chain.run("Hello!")
Drag options to blanks, or click blank then click option'
ALLMChain
BSimpleChain
CChainList
DLangChain
Attempts:
3 left
💡 Hint
Common Mistakes
Using a class that does not exist in LangChain.
Confusing chain classes with other utilities.
2fill in blank
medium

Complete the code to import the base class for chains in LangChain.

LangChain
from langchain.chains import [1]
Drag options to blanks, or click blank then click option'
AChainBase
BChainable
CChain
DBaseChain
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'BaseChain' instead of 'Chain'.
Guessing class names without checking documentation.
3fill in blank
hard

Fix the error in the code to create a chain that uses a prompt template.

LangChain
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")
Drag options to blanks, or click blank then click option'
AChainPrompt
BPromptChain
CTemplatePrompt
DPromptTemplate
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect class names for prompt templates.
Confusing prompt classes with chain classes.
4fill in blank
hard

Fill both blanks to create a chain that uses a prompt template and runs with input.

LangChain
from langchain.chains import [1]
from langchain.prompts import [2]

chain = [1](llm=llm, prompt=[2](template="Hello, {user}!") )
result = chain.run(user="Bob")
Drag options to blanks, or click blank then click option'
ALLMChain
BPromptTemplate
CSimpleChain
DChainBase
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up chain and prompt class names.
Using classes that do not exist in LangChain.
5fill in blank
hard

Fill all three blanks to create a chain that uses a prompt template, runs with input, and prints the result.

LangChain
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)
Drag options to blanks, or click blank then click option'
ALLMChain
BPromptTemplate
CSimpleChain
DChainBase
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong class names for chain or prompt.
Not matching variable names correctly.