Model Pipeline - Chains (sequential, router)
This pipeline shows how chains combine multiple AI tasks in order. A sequential chain runs steps one after another. A router chain decides which step to run based on input.
Jump into concepts and practice - no test required
This pipeline shows how chains combine multiple AI tasks in order. A sequential chain runs steps one after another. A router chain decides which step to run based on input.
Loss
0.5 |****
0.4 |***
0.3 |**
0.2 |*
0.1 |
1 2 3 4 Epochs
| Epoch | Loss ↓ | Accuracy ↑ | Observation |
|---|---|---|---|
| 1 | 0.45 | 0.6 | Initial training with random routing decisions. |
| 2 | 0.3 | 0.75 | Router learns to pick better chains, improving accuracy. |
| 3 | 0.2 | 0.85 | Sequential chain steps optimize output quality. |
| 4 | 0.15 | 0.9 | Model converges with stable routing and responses. |
def router_func(input_text):
if 'weather' in input_text.lower():
return 'weather_step'
else:
return 'default_step'
steps = {
'weather_step': lambda x: 'It is sunny',
'default_step': lambda x: 'I do not understand'
}
router_chain = RouterChain(steps=steps, router_function=router_func)
result = router_chain.run('What is the weather today?')steps = {
'step1': lambda x: 'Hello',
'step2': lambda x: 'Bye'
}
def router_func(input_text):
if 'hello' in input_text:
return 'step1'
else:
return 'step3'
router_chain = RouterChain(steps=steps, router_function=router_func)
result = router_chain.run('hello there')