Branching
SimpleBranchingPipeline ¶
Bases: BaseComponent
A simple branching pipeline for executing multiple branches.
Attributes:
Name | Type | Description |
---|---|---|
branches |
List[BaseComponent]
|
The list of branches to be executed. |
Example
Source code in libs/kotaemon/kotaemon/llms/branching.py
add_branch ¶
Add a new branch to the pipeline.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
component
|
BaseComponent
|
The branch component to be added. |
required |
run ¶
Execute the pipeline by running each branch and return the outputs as a list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**prompt_kwargs
|
Keyword arguments for the branches. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
List |
The outputs of each branch as a list. |
Source code in libs/kotaemon/kotaemon/llms/branching.py
GatedBranchingPipeline ¶
Bases: SimpleBranchingPipeline
A simple gated branching pipeline for executing multiple branches based on a condition.
This class extends the SimpleBranchingPipeline class and adds the ability to execute the branches until a branch returns a non-empty output based on a condition.
Attributes:
Name | Type | Description |
---|---|---|
branches |
List[BaseComponent]
|
The list of branches to be executed. |
Example
Source code in libs/kotaemon/kotaemon/llms/branching.py
run ¶
Execute the pipeline by running each branch and return the output of the first branch that returns a non-empty output based on the provided condition.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
condition_text
|
str
|
The condition text to evaluate for each branch. Default to None. |
None
|
**prompt_kwargs
|
Keyword arguments for the branches. |
{}
|
Returns:
Type | Description |
---|---|
Union[OutputType, None]: The output of the first branch that satisfies the |
|
condition, or None if no branch satisfies the condition. |
Raises:
Type | Description |
---|---|
ValueError
|
If condition_text is None |