0
0
Prompt Engineering / GenAIml~20 mins

Chains (sequential, router) in Prompt Engineering / GenAI - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Chain Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding Sequential Chains

In a sequential chain, multiple steps are executed one after another. Which statement best describes how data flows through a sequential chain?

AAll steps run independently and their outputs are combined at the end.
BEach step receives input from the previous step's output and passes its output to the next step.
CThe first step receives all inputs and the last step produces all outputs without intermediate processing.
DSteps randomly select inputs from the original data without following order.
Attempts:
2 left
💡 Hint

Think about a relay race where one runner passes the baton to the next.

Model Choice
intermediate
1:30remaining
Choosing a Router Chain Use Case

You want to build a system that decides which specialized model to use based on the input type (e.g., text, image, or audio). Which chain type is best suited for this task?

ASequential chain that processes all inputs through every model in order.
BParallel chain that runs all models simultaneously and averages their outputs.
CRouter chain that selects the appropriate model based on input characteristics.
DSingle model chain that handles all input types without selection.
Attempts:
2 left
💡 Hint

Consider a traffic controller directing cars to different lanes based on their type.

Predict Output
advanced
2:00remaining
Output of a Sequential Chain Code

What is the output of the following pseudo-code for a sequential chain?

Prompt Engineering / GenAI
def step1(x):
    return x + 2

def step2(y):
    return y * 3

input_value = 4
output = step2(step1(input_value))
print(output)
A20
B14
C12
D18
Attempts:
2 left
💡 Hint

Calculate step1 first, then use its output in step2.

Metrics
advanced
2:00remaining
Evaluating Router Chain Performance

You have a router chain that directs inputs to three models. After testing, you get these accuracies: Model A: 90%, Model B: 85%, Model C: 80%. The router correctly routes 95% of inputs. What is the approximate overall accuracy of the router chain?

A88.25%
B92.50%
C90.00%
D85.75%
Attempts:
2 left
💡 Hint

Calculate weighted accuracy considering routing correctness and model accuracies.

🔧 Debug
expert
2:30remaining
Debugging a Router Chain Routing Error

Given this router chain pseudo-code, what causes the routing error?

def router(input):
    if 'image' in input:
        return 'model_image'
    elif 'text' in input:
        return 'model_text'
    else:
        return 'model_default'

input_data = 'audio file'
selected_model = router(input_data)
print(selected_model)
AThe router does not handle 'audio' inputs, so it returns 'model_default' which may not exist.
BThe condition 'if "image" in input' causes a syntax error due to missing colon.
CThe input_data variable is not defined before calling router.
DThe router function returns a list instead of a string, causing a type error.
Attempts:
2 left
💡 Hint

Check how the router handles inputs not matching 'image' or 'text'.