Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a sequential chain that runs two steps in order.
Prompt Engineering / GenAI
from langchain.chains import SequentialChain chain = SequentialChain(chains=[chain1, [1]], input_variables=["input"], output_variables=["output"]) result = chain.run("Hello")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a chain variable that is not defined.
Swapping the order of chains.
✗ Incorrect
The second chain in the sequence should be 'chain2' to run after 'chain1'.
2fill in blank
mediumComplete the code to define a router chain that selects chains based on input keys.
Prompt Engineering / GenAI
from langchain.chains.router import RouterChain router = RouterChain(chains={'sales': sales_chain, 'support': [1], default_chain=default_chain) response = router.run("support request")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a chain that does not match the key.
Forgetting to include the correct chain in the dictionary.
✗ Incorrect
The router should map the 'support' key to 'support_chain' to handle support requests.
3fill in blank
hardFix the error in the sequential chain code by filling the blank correctly.
Prompt Engineering / GenAI
from langchain.chains import SequentialChain chain = SequentialChain(chains=[chain1, chain2], input_variables=["input"], output_variables=[[1]]) result = chain.run("Test")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name not matching the chain's output.
Not using a list for output_variables.
✗ Incorrect
The output_variables must match the output key from the chains, commonly 'output'.
4fill in blank
hardFill both blanks to create a router chain that routes 'billing' and 'tech' requests correctly.
Prompt Engineering / GenAI
router = RouterChain(chains=[1], default_chain=default_chain) response = router.run("billing issue")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the chains for keys.
Using default_chain instead of specific chains.
✗ Incorrect
The router dictionary must map 'billing' to billing_chain and 'tech' to tech_chain for correct routing.
5fill in blank
hardFill all three blanks to build a sequential chain with correct input and output variables.
Prompt Engineering / GenAI
chain = SequentialChain(chains=[chainA, chainB], input_variables=[[1]], output_variables=[[2]]) result = chain.run([3])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names for input or output.
Passing a string instead of a dictionary to run.
✗ Incorrect
Input variable is 'user_input', output variable is 'final_output', and run method input is a dict with 'user_input' key.