0
0
LangChainframework~10 mins

Sequential chains in LangChain - Interactive Code 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 sequential chain with two steps.

LangChain
from langchain.chains import SequentialChain
from langchain.llms import OpenAI

llm = OpenAI()

chain = SequentialChain(chains=[[1]], input_variables=["input"], output_variables=["output"])
Drag options to blanks, or click blank then click option'
ASequentialChain
Bchain1, chain2
Cllm
Dchain1
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the llm object directly instead of a chain.
Passing multiple chains without wrapping them in a list.
Using the class name instead of an instance.
2fill in blank
medium

Complete the code to run the sequential chain with the correct input variable.

LangChain
result = chain.run([1]="Hello")
Drag options to blanks, or click blank then click option'
Ainput
Boutput
Ctext
Dquery
Attempts:
3 left
💡 Hint
Common Mistakes
Using the output variable as input.
Using a variable name not defined in the chain.
3fill in blank
hard

Fix the error in the code by choosing the correct method to add chains to the SequentialChain.

LangChain
from langchain.chains import SequentialChain

chain = SequentialChain()
chain.[1](chain1)
Drag options to blanks, or click blank then click option'
Aadd
Badd_chain
Cappend
Dextend
Attempts:
3 left
💡 Hint
Common Mistakes
Using list methods like append or extend which are not defined.
Using a method name that does not exist in the class.
4fill in blank
hard

Fill both blanks to create a SequentialChain with two chains and specify the correct input and output variables.

LangChain
chain = SequentialChain(chains=[[1], [2]], input_variables=["input"], output_variables=["final_output"])
Drag options to blanks, or click blank then click option'
Achain1
Bchain2
Cchain3
Dchain4
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same chain twice.
Using chains not defined in the code.
5fill in blank
hard

Fill all three blanks to define a SequentialChain with input, output, and intermediate variables correctly.

LangChain
chain = SequentialChain(
    chains=[[1], [2]],
    input_variables=[[3]],
    output_variables=["result"]
)
Drag options to blanks, or click blank then click option'
AchainA
BchainB
C"user_input"
D"input_text"
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the input variable name.
Using undefined chain names.