gllm-pipeline-binary 0.4.21__cp311-cp311-macosx_13_0_arm64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- gllm_pipeline/__init__.pyi +0 -0
- gllm_pipeline/alias.pyi +7 -0
- gllm_pipeline/exclusions/__init__.pyi +4 -0
- gllm_pipeline/exclusions/exclusion_manager.pyi +74 -0
- gllm_pipeline/exclusions/exclusion_set.pyi +46 -0
- gllm_pipeline/pipeline/__init__.pyi +4 -0
- gllm_pipeline/pipeline/composer/__init__.pyi +8 -0
- gllm_pipeline/pipeline/composer/composer.pyi +350 -0
- gllm_pipeline/pipeline/composer/guard_composer.pyi +58 -0
- gllm_pipeline/pipeline/composer/if_else_composer.pyi +57 -0
- gllm_pipeline/pipeline/composer/parallel_composer.pyi +47 -0
- gllm_pipeline/pipeline/composer/switch_composer.pyi +57 -0
- gllm_pipeline/pipeline/composer/toggle_composer.pyi +48 -0
- gllm_pipeline/pipeline/pipeline.pyi +280 -0
- gllm_pipeline/pipeline/states.pyi +139 -0
- gllm_pipeline/router/__init__.pyi +6 -0
- gllm_pipeline/router/aurelio_semantic_router/__init__.pyi +3 -0
- gllm_pipeline/router/aurelio_semantic_router/aurelio_semantic_router.pyi +86 -0
- gllm_pipeline/router/aurelio_semantic_router/bytes_compat_route.pyi +40 -0
- gllm_pipeline/router/aurelio_semantic_router/encoders/__init__.pyi +5 -0
- gllm_pipeline/router/aurelio_semantic_router/encoders/em_invoker_encoder.pyi +46 -0
- gllm_pipeline/router/aurelio_semantic_router/encoders/langchain_encoder.pyi +50 -0
- gllm_pipeline/router/aurelio_semantic_router/encoders/tei_encoder.pyi +49 -0
- gllm_pipeline/router/aurelio_semantic_router/index/__init__.pyi +4 -0
- gllm_pipeline/router/aurelio_semantic_router/index/aurelio_index.pyi +65 -0
- gllm_pipeline/router/aurelio_semantic_router/index/azure_ai_search_aurelio_index.pyi +71 -0
- gllm_pipeline/router/aurelio_semantic_router/index/vector_store_adapter_index.pyi +119 -0
- gllm_pipeline/router/lm_based_router.pyi +60 -0
- gllm_pipeline/router/preset/__init__.pyi +0 -0
- gllm_pipeline/router/preset/aurelio/__init__.pyi +0 -0
- gllm_pipeline/router/preset/aurelio/router_image_domain_specific.pyi +21 -0
- gllm_pipeline/router/preset/lm_based/__init__.pyi +0 -0
- gllm_pipeline/router/preset/lm_based/router_image_domain_specific.pyi +14 -0
- gllm_pipeline/router/preset/preset_loader.pyi +24 -0
- gllm_pipeline/router/router.pyi +46 -0
- gllm_pipeline/router/rule_based_router.pyi +80 -0
- gllm_pipeline/router/similarity_based_router.pyi +72 -0
- gllm_pipeline/router/utils.pyi +26 -0
- gllm_pipeline/steps/__init__.pyi +17 -0
- gllm_pipeline/steps/_func.pyi +958 -0
- gllm_pipeline/steps/branching_step.pyi +24 -0
- gllm_pipeline/steps/component_step.pyi +82 -0
- gllm_pipeline/steps/composite_step.pyi +65 -0
- gllm_pipeline/steps/conditional_step.pyi +161 -0
- gllm_pipeline/steps/guard_step.pyi +71 -0
- gllm_pipeline/steps/log_step.pyi +53 -0
- gllm_pipeline/steps/map_reduce_step.pyi +92 -0
- gllm_pipeline/steps/no_op_step.pyi +40 -0
- gllm_pipeline/steps/parallel_step.pyi +128 -0
- gllm_pipeline/steps/pipeline_step.pyi +231 -0
- gllm_pipeline/steps/state_operator_step.pyi +75 -0
- gllm_pipeline/steps/step_error_handler/__init__.pyi +6 -0
- gllm_pipeline/steps/step_error_handler/empty_step_error_handler.pyi +20 -0
- gllm_pipeline/steps/step_error_handler/fallback_step_error_handler.pyi +24 -0
- gllm_pipeline/steps/step_error_handler/keep_step_error_handler.pyi +9 -0
- gllm_pipeline/steps/step_error_handler/raise_step_error_handler.pyi +9 -0
- gllm_pipeline/steps/step_error_handler/step_error_handler.pyi +46 -0
- gllm_pipeline/steps/subgraph_step.pyi +90 -0
- gllm_pipeline/steps/terminator_step.pyi +57 -0
- gllm_pipeline/types.pyi +10 -0
- gllm_pipeline/utils/__init__.pyi +9 -0
- gllm_pipeline/utils/async_utils.pyi +21 -0
- gllm_pipeline/utils/copy.pyi +11 -0
- gllm_pipeline/utils/error_handling.pyi +61 -0
- gllm_pipeline/utils/graph.pyi +16 -0
- gllm_pipeline/utils/has_inputs_mixin.pyi +50 -0
- gllm_pipeline/utils/input_map.pyi +12 -0
- gllm_pipeline/utils/mermaid.pyi +29 -0
- gllm_pipeline/utils/retry_converter.pyi +25 -0
- gllm_pipeline/utils/step_execution.pyi +19 -0
- gllm_pipeline.build/.gitignore +1 -0
- gllm_pipeline.cpython-311-darwin.so +0 -0
- gllm_pipeline.pyi +86 -0
- gllm_pipeline_binary-0.4.21.dist-info/METADATA +105 -0
- gllm_pipeline_binary-0.4.21.dist-info/RECORD +77 -0
- gllm_pipeline_binary-0.4.21.dist-info/WHEEL +5 -0
- gllm_pipeline_binary-0.4.21.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
from gllm_core.utils.retry import RetryConfig as RetryConfig
|
|
2
|
+
from gllm_datastore.cache.cache import BaseCache as BaseCache
|
|
3
|
+
from gllm_pipeline.alias import InputMapSpec as InputMapSpec
|
|
4
|
+
from gllm_pipeline.pipeline.composer.composer import Composer as Composer
|
|
5
|
+
from gllm_pipeline.schema import PipelineSteps as PipelineSteps
|
|
6
|
+
from gllm_pipeline.steps.pipeline_step import BasePipelineStep as BasePipelineStep
|
|
7
|
+
from gllm_pipeline.steps.step_error_handler.step_error_handler import BaseStepErrorHandler as BaseStepErrorHandler
|
|
8
|
+
from typing import Any, Self
|
|
9
|
+
|
|
10
|
+
class ParallelComposer:
|
|
11
|
+
'''Fluent builder for a parallel step.
|
|
12
|
+
|
|
13
|
+
Usage:
|
|
14
|
+
composer.parallel(name="p").fork(step_a).fork([step_b1, step_b2]).end()
|
|
15
|
+
|
|
16
|
+
The builder collects forks as branches and constructs a `ParallelStep`
|
|
17
|
+
using the functional helper `_func.parallel(...)`.
|
|
18
|
+
'''
|
|
19
|
+
def __init__(self, parent: Composer, *, squash: bool = True, input_map: InputMapSpec | None = None, retry_config: RetryConfig | None = None, error_handler: BaseStepErrorHandler | None = None, cache_store: BaseCache | None = None, cache_config: dict[str, Any] | None = None, name: str | None = None) -> None:
|
|
20
|
+
"""Initialize the ParallelComposer.
|
|
21
|
+
|
|
22
|
+
Args:
|
|
23
|
+
parent (Composer): The parent composer instance.
|
|
24
|
+
squash (bool, optional): Whether to squash execution into a single node (async gather).
|
|
25
|
+
Defaults to True.
|
|
26
|
+
input_map (InputMapSpec | None, optional): Unified input mapping for all branches. Defaults to None.
|
|
27
|
+
retry_config (RetryConfig | None, optional): Retry configuration. Defaults to None.
|
|
28
|
+
error_handler (BaseStepErrorHandler | None, optional): Error handler. Defaults to None.
|
|
29
|
+
cache_store (BaseCache | None, optional): Optional cache store. Defaults to None.
|
|
30
|
+
cache_config (dict[str, Any] | None, optional): Optional cache config. Defaults to None.
|
|
31
|
+
name (str | None, optional): Optional name for the resulting step. Defaults to None.
|
|
32
|
+
"""
|
|
33
|
+
def fork(self, branch: BasePipelineStep | list[BasePipelineStep]) -> Self:
|
|
34
|
+
"""Add a fork (branch) to execute in parallel.
|
|
35
|
+
|
|
36
|
+
Args:
|
|
37
|
+
branch (BasePipelineStep | list[BasePipelineStep]): Step(s) for this fork.
|
|
38
|
+
|
|
39
|
+
Returns:
|
|
40
|
+
Self: The builder instance for chaining.
|
|
41
|
+
"""
|
|
42
|
+
def end(self) -> Composer:
|
|
43
|
+
"""Finalize and append the parallel step to the parent composer.
|
|
44
|
+
|
|
45
|
+
Returns:
|
|
46
|
+
Composer: The parent composer for continued chaining.
|
|
47
|
+
"""
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
from gllm_core.schema import Component as Component
|
|
2
|
+
from gllm_core.utils.retry import RetryConfig as RetryConfig
|
|
3
|
+
from gllm_datastore.cache.cache import BaseCache as BaseCache
|
|
4
|
+
from gllm_pipeline.alias import InputMapSpec as InputMapSpec
|
|
5
|
+
from gllm_pipeline.pipeline.composer.composer import Composer as Composer
|
|
6
|
+
from gllm_pipeline.steps.pipeline_step import BasePipelineStep as BasePipelineStep
|
|
7
|
+
from gllm_pipeline.steps.step_error_handler.step_error_handler import BaseStepErrorHandler as BaseStepErrorHandler
|
|
8
|
+
from typing import Any, Callable, Self
|
|
9
|
+
|
|
10
|
+
class SwitchComposer:
|
|
11
|
+
'''Fluent builder for a switch conditional.
|
|
12
|
+
|
|
13
|
+
Usage:
|
|
14
|
+
composer.switch(cond).case("A", step_a).case("B", step_b).end()
|
|
15
|
+
|
|
16
|
+
Optionally call `.default(...)` to set a fallback branch.
|
|
17
|
+
'''
|
|
18
|
+
def __init__(self, parent: Composer, condition: Component | Callable[[dict[str, Any]], str], output_state: str | None = None, input_map: InputMapSpec | None = None, retry_config: RetryConfig | None = None, error_handler: BaseStepErrorHandler | None = None, cache_store: BaseCache | None = None, cache_config: dict[str, Any] | None = None, name: str | None = None) -> None:
|
|
19
|
+
'''Initialize the SwitchComposer.
|
|
20
|
+
|
|
21
|
+
Args:
|
|
22
|
+
parent (Composer): The parent composer instance.
|
|
23
|
+
condition (Component | Callable[[dict[str, Any]], str]): The condition to evaluate.
|
|
24
|
+
output_state (str | None, optional): Optional state key to store condition result. Defaults to None.
|
|
25
|
+
input_map (InputMapSpec | None, optional): Unified input mapping for the condition. Defaults to None.
|
|
26
|
+
retry_config (RetryConfig | None, optional): Retry configuration. Defaults to None.
|
|
27
|
+
error_handler (BaseStepErrorHandler | None, optional): Error handler. Defaults to None.
|
|
28
|
+
cache_store (BaseCache | None, optional): Optional cache store. Defaults to None.
|
|
29
|
+
cache_config (dict[str, Any] | None, optional): Optional cache config. Defaults to None.
|
|
30
|
+
name (str | None, optional): Optional name for the resulting step. Defaults to None, in which case
|
|
31
|
+
a name will be auto-generated with the prefix "Switch_".
|
|
32
|
+
'''
|
|
33
|
+
def case(self, key: str, branch: BasePipelineStep | list[BasePipelineStep]) -> Self:
|
|
34
|
+
"""Add a case branch.
|
|
35
|
+
|
|
36
|
+
Args:
|
|
37
|
+
key (str): Case key to match against condition result.
|
|
38
|
+
branch (BasePipelineStep | list[BasePipelineStep]): Step(s) to execute for this case.
|
|
39
|
+
|
|
40
|
+
Returns:
|
|
41
|
+
Self: The builder instance for chaining.
|
|
42
|
+
"""
|
|
43
|
+
def default(self, branch: BasePipelineStep | list[BasePipelineStep]) -> Self:
|
|
44
|
+
"""Set the default branch for unmatched cases.
|
|
45
|
+
|
|
46
|
+
Args:
|
|
47
|
+
branch (BasePipelineStep | list[BasePipelineStep]): Default fallback branch.
|
|
48
|
+
|
|
49
|
+
Returns:
|
|
50
|
+
Self: The builder instance for chaining.
|
|
51
|
+
"""
|
|
52
|
+
def end(self) -> Composer:
|
|
53
|
+
"""Finalize and append the switch conditional to the parent composer.
|
|
54
|
+
|
|
55
|
+
Returns:
|
|
56
|
+
Composer: The parent composer for continued chaining.
|
|
57
|
+
"""
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
from gllm_core.schema import Component as Component
|
|
2
|
+
from gllm_core.utils.retry import RetryConfig as RetryConfig
|
|
3
|
+
from gllm_datastore.cache.cache import BaseCache as BaseCache
|
|
4
|
+
from gllm_pipeline.alias import InputMapSpec as InputMapSpec
|
|
5
|
+
from gllm_pipeline.pipeline.composer.composer import Composer as Composer
|
|
6
|
+
from gllm_pipeline.steps.pipeline_step import BasePipelineStep as BasePipelineStep
|
|
7
|
+
from gllm_pipeline.steps.step_error_handler.step_error_handler import BaseStepErrorHandler as BaseStepErrorHandler
|
|
8
|
+
from typing import Any, Callable, Self
|
|
9
|
+
|
|
10
|
+
class ToggleComposer:
|
|
11
|
+
"""Fluent builder for a toggle conditional.
|
|
12
|
+
|
|
13
|
+
Usage:
|
|
14
|
+
composer.toggle(condition).then(enabled_branch).end()
|
|
15
|
+
|
|
16
|
+
After setting the enabled branch, call `.end()` to append the toggle step and
|
|
17
|
+
return back to the parent `Composer`.
|
|
18
|
+
"""
|
|
19
|
+
def __init__(self, parent: Composer, condition: Component | Callable[[dict[str, Any]], bool] | str, output_state: str | None = None, input_map: InputMapSpec | None = None, retry_config: RetryConfig | None = None, error_handler: BaseStepErrorHandler | None = None, cache_store: BaseCache | None = None, cache_config: dict[str, Any] | None = None, name: str | None = None) -> None:
|
|
20
|
+
'''Initialize the ToggleComposer.
|
|
21
|
+
|
|
22
|
+
Args:
|
|
23
|
+
parent (Composer): The parent composer instance.
|
|
24
|
+
condition (Component | Callable[[dict[str, Any]], bool] | str): The condition to evaluate.
|
|
25
|
+
output_state (str | None, optional): Optional state key to store condition result. Defaults to None.
|
|
26
|
+
input_map (InputMapSpec | None, optional): Unified input mapping for the condition. Defaults to None.
|
|
27
|
+
retry_config (RetryConfig | None, optional): Retry configuration. Defaults to None.
|
|
28
|
+
error_handler (BaseStepErrorHandler | None, optional): Error handler. Defaults to None.
|
|
29
|
+
cache_store (BaseCache | None, optional): Optional cache store. Defaults to None.
|
|
30
|
+
cache_config (dict[str, Any] | None, optional): Optional cache config. Defaults to None.
|
|
31
|
+
name (str | None, optional): Optional name for the resulting step. Defaults to None, in which case
|
|
32
|
+
a name will be auto-generated with the prefix "Toggle_".
|
|
33
|
+
'''
|
|
34
|
+
def then(self, branch: BasePipelineStep | list[BasePipelineStep]) -> Self:
|
|
35
|
+
"""Define the branch to execute when the condition is true.
|
|
36
|
+
|
|
37
|
+
Args:
|
|
38
|
+
branch (BasePipelineStep | list[BasePipelineStep]): The step(s) for the enabled branch.
|
|
39
|
+
|
|
40
|
+
Returns:
|
|
41
|
+
Self: The builder instance for chaining.
|
|
42
|
+
"""
|
|
43
|
+
def end(self) -> Composer:
|
|
44
|
+
"""Finalize and append the toggle step to the parent composer.
|
|
45
|
+
|
|
46
|
+
Returns:
|
|
47
|
+
Composer: The parent composer for continued chaining.
|
|
48
|
+
"""
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
from _typeshed import Incomplete
|
|
2
|
+
from gllm_datastore.cache.cache import BaseCache as BaseCache
|
|
3
|
+
from gllm_pipeline.alias import PipelineState as PipelineState
|
|
4
|
+
from gllm_pipeline.exclusions import ExclusionManager as ExclusionManager, ExclusionSet as ExclusionSet
|
|
5
|
+
from gllm_pipeline.pipeline.composer import Composer as Composer
|
|
6
|
+
from gllm_pipeline.pipeline.states import RAGState as RAGState
|
|
7
|
+
from gllm_pipeline.steps.pipeline_step import BasePipelineStep as BasePipelineStep
|
|
8
|
+
from gllm_pipeline.steps.terminator_step import TerminatorStep as TerminatorStep
|
|
9
|
+
from gllm_pipeline.utils.graph import create_edge as create_edge
|
|
10
|
+
from gllm_pipeline.utils.mermaid import MERMAID_HEADER as MERMAID_HEADER, combine_mermaid_diagrams as combine_mermaid_diagrams, extract_step_diagrams as extract_step_diagrams
|
|
11
|
+
from langgraph.graph import StateGraph
|
|
12
|
+
from langgraph.graph.state import CompiledStateGraph as CompiledStateGraph
|
|
13
|
+
from pydantic import BaseModel
|
|
14
|
+
from typing import Any, TypedDict
|
|
15
|
+
|
|
16
|
+
INDENTATION: str
|
|
17
|
+
|
|
18
|
+
class Pipeline:
|
|
19
|
+
'''Represents a sequence of steps executed in order, forming a pipeline.
|
|
20
|
+
|
|
21
|
+
A pipeline can have zero or more steps. When a pipeline has no steps (empty list), it acts as a
|
|
22
|
+
pass-through pipeline that simply returns the input state unchanged. This is useful when using
|
|
23
|
+
the pipe (|) operator to define RAG State without requiring explicit steps.
|
|
24
|
+
|
|
25
|
+
Attributes:
|
|
26
|
+
steps (list[BasePipelineStep]): List of steps to be executed in the pipeline. Can be empty
|
|
27
|
+
for a pass-through pipeline.
|
|
28
|
+
state_type (type): The type of state used in the pipeline. Defaults to RAGState.
|
|
29
|
+
recursion_limit (int): The maximum number of steps allowed.
|
|
30
|
+
name (str | None): A name for this pipeline. Used when this pipeline is included as a subgraph.
|
|
31
|
+
Defaults to None, in which case the name will be "Subgraph" followed by a unique identifier.
|
|
32
|
+
exclusions (ExclusionManager): The exclusion manager for this pipeline.
|
|
33
|
+
|
|
34
|
+
Usage examples:
|
|
35
|
+
# Basic pipeline with steps
|
|
36
|
+
```python
|
|
37
|
+
pipeline = Pipeline([retrieval_step, generation_step, terminator_step])
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
# Empty pipeline (pass-through)
|
|
41
|
+
```python
|
|
42
|
+
pipeline = Pipeline([])
|
|
43
|
+
pipeline = Pipeline(None)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
# Pipeline with custom state type
|
|
47
|
+
```python
|
|
48
|
+
class CustomState(TypedDict):
|
|
49
|
+
user_query: str
|
|
50
|
+
context: str
|
|
51
|
+
response: str
|
|
52
|
+
|
|
53
|
+
pipeline = Pipeline([retrieval_step, generation_step], state_type=CustomState)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
# Named pipeline for subgraph usage
|
|
57
|
+
```python
|
|
58
|
+
pipeline = Pipeline([retrieval_step, generation_step], name="rag_pipeline")
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
# Pipeline with caching
|
|
62
|
+
```python
|
|
63
|
+
pipeline = Pipeline(
|
|
64
|
+
[retrieval_step, generation_step],
|
|
65
|
+
cache_store=cache_store,
|
|
66
|
+
cache_config={"ttl": 3600, "name": "rag_cache"}
|
|
67
|
+
)
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
# Using pipe (|) operator to combine steps
|
|
71
|
+
```python
|
|
72
|
+
pipeline = retrieval_step | generation_step | terminator_step
|
|
73
|
+
```
|
|
74
|
+
# Using pipe (|) operator to combine step with pipeline
|
|
75
|
+
```python
|
|
76
|
+
pipeline = Pipeline([retrieval_step, generation_step]) | terminator_step
|
|
77
|
+
```
|
|
78
|
+
# Using pipe (|) operator to combine pipelines
|
|
79
|
+
```python
|
|
80
|
+
pipeline1 = Pipeline([retrieval_step])
|
|
81
|
+
pipeline2 = Pipeline([generation_step, terminator_step])
|
|
82
|
+
combined_pipeline = pipeline1 | pipeline2
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
# Configure step exclusion after initialization (set-only)
|
|
86
|
+
```python
|
|
87
|
+
log_step = log(name="log_step", ...)
|
|
88
|
+
retrieval_step = step(name="retrieval_step", ...)
|
|
89
|
+
generation_step = step(name="generation_step", ...)
|
|
90
|
+
pipeline = Pipeline([log_step, retrieval_step, generation_step])
|
|
91
|
+
pipeline.exclusions.exclude("log_step") # Skip logging step
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
# Configure composite step exclusion
|
|
95
|
+
```python
|
|
96
|
+
log_step = log(name="log_step", ...)
|
|
97
|
+
retrieval_a_step = step(name="retrieval_a_step", ...)
|
|
98
|
+
retrieval_b_step = step(name="retrieval_b_step", ...)
|
|
99
|
+
parallel_step = parallel(
|
|
100
|
+
name="parallel_step", {"retrieval_a": retrieval_a_step, "retrieval_b": retrieval_b_step},
|
|
101
|
+
)
|
|
102
|
+
pipeline = Pipeline([log_step, parallel_step])
|
|
103
|
+
pipeline.exclusions.exclude("parallel_step") # Skip the entire parallel step
|
|
104
|
+
pipeline.exclusions.exclude("parallel_step.retrieval_a") # Skip retrieval_a step
|
|
105
|
+
pipeline.exclusions.exclude("parallel_step.retrieval_b") # Skip retrieval_b step
|
|
106
|
+
```
|
|
107
|
+
'''
|
|
108
|
+
name: Incomplete
|
|
109
|
+
steps: Incomplete
|
|
110
|
+
recursion_limit: Incomplete
|
|
111
|
+
def __init__(self, steps: list[BasePipelineStep] | None = None, state_type: TypedDict | type[BaseModel] = ..., input_type: TypedDict | type[BaseModel] | None = None, output_type: TypedDict | type[BaseModel] | None = None, context_schema: TypedDict | type[BaseModel] | None = None, recursion_limit: int = 30, name: str | None = None, cache_store: BaseCache | None = None, cache_config: dict[str, Any] | None = None) -> None:
|
|
112
|
+
'''Initializes the Pipeline with the given steps and state type.
|
|
113
|
+
|
|
114
|
+
Args:
|
|
115
|
+
steps (list[BasePipelineStep] | None, optional): List of steps to be executed in the pipeline.
|
|
116
|
+
Defaults to None, in which case the steps will be `[]` and simply returns the input state unchanged.
|
|
117
|
+
state_type (TypedDict | type[BaseModel], optional): The type of pipeline\'s overall internal state.
|
|
118
|
+
Could be a TypedDict or a Pydantic BaseModel. Defaults to RAGState.
|
|
119
|
+
input_type (TypedDict | type[BaseModel] | None, optional): The type of pipeline\'s input state.
|
|
120
|
+
This state should be compatible with the pipeline\'s `state_type`.
|
|
121
|
+
Could be a TypedDict or a Pydantic BaseModel. Defaults to None, in which case the input state type
|
|
122
|
+
will be the same as the pipeline\'s `state_type`.
|
|
123
|
+
output_type (TypedDict | type[BaseModel] | None, optional): The type of pipeline\'s output state.
|
|
124
|
+
This state should be compatible with the pipeline\'s `state_type`.
|
|
125
|
+
Could be a TypedDict or a Pydantic BaseModel. Defaults to None, in which case the output state type
|
|
126
|
+
will be the same as the pipeline\'s `state_type`.
|
|
127
|
+
context_schema (TypedDict | type[BaseModel] | None, optional): The type of pipeline\'s runtime context.
|
|
128
|
+
Defaults to None, in which case no context schema will be used.
|
|
129
|
+
recursion_limit (int, optional): The maximum number of steps allowed. Defaults to 30.
|
|
130
|
+
name (str | None, optional): A name for this pipeline. Used when this pipeline is included as a subgraph.
|
|
131
|
+
Defaults to None, in which case the name will be "Subgraph" followed by a unique identifier.
|
|
132
|
+
cache_store ("BaseCache" | None, optional): The cache store to use for caching pipeline results.
|
|
133
|
+
Defaults to None. Defaults to None, in which case no caching will be used.
|
|
134
|
+
cache_config (dict[str, Any] | None, optional): Configuration for the cache store.
|
|
135
|
+
Defaults to None, in which case no cache configuration will be used.
|
|
136
|
+
The cache config should be a dictionary with the following keys:
|
|
137
|
+
1. key_func (Callable | None, optional): A function to generate cache keys.
|
|
138
|
+
Defaults to None, in which case the cache instance will use its own key function.
|
|
139
|
+
2. name (str | None, optional): The name of the cache.
|
|
140
|
+
Defaults to None, in which case the cache instance will use its own key function.
|
|
141
|
+
3. ttl (int | None, optional): The time-to-live for the cache.
|
|
142
|
+
Defaults to None, in which case the cache will not have a TTL.
|
|
143
|
+
4. matching_strategy (str | None, optional): The strategy for matching cache keys.
|
|
144
|
+
Defaults to None, in which case the cache instance will use "exact".
|
|
145
|
+
5. matching_config (dict[str, Any] | None, optional): Configuration for the matching strategy.
|
|
146
|
+
Defaults to None, in which case the cache instance will use its
|
|
147
|
+
own default matching strategy configuration.
|
|
148
|
+
'''
|
|
149
|
+
@property
|
|
150
|
+
def state_type(self) -> type:
|
|
151
|
+
"""The current state type of the pipeline.
|
|
152
|
+
|
|
153
|
+
Returns:
|
|
154
|
+
type: The current state type.
|
|
155
|
+
"""
|
|
156
|
+
@state_type.setter
|
|
157
|
+
def state_type(self, new_state_type: TypedDict | type[BaseModel]) -> None:
|
|
158
|
+
"""Sets a new state type for the pipeline.
|
|
159
|
+
|
|
160
|
+
Args:
|
|
161
|
+
new_state_type (TypedDict | type[BaseModel]): The new state type to set.
|
|
162
|
+
|
|
163
|
+
Note:
|
|
164
|
+
This operation will rebuild the pipeline graph if it has already been initialized, which can be
|
|
165
|
+
computationally expensive for complex pipelines.
|
|
166
|
+
It is recommended to set the state type before building the pipeline graph.
|
|
167
|
+
"""
|
|
168
|
+
@property
|
|
169
|
+
def graph(self) -> StateGraph:
|
|
170
|
+
"""The graph representation of the pipeline.
|
|
171
|
+
|
|
172
|
+
If the graph doesn't exist yet, it will be built automatically.
|
|
173
|
+
|
|
174
|
+
Returns:
|
|
175
|
+
StateGraph: The graph representation of the pipeline.
|
|
176
|
+
"""
|
|
177
|
+
@property
|
|
178
|
+
def exclusions(self) -> ExclusionManager:
|
|
179
|
+
"""Get the exclusion manager for this pipeline.
|
|
180
|
+
|
|
181
|
+
Returns:
|
|
182
|
+
ExclusionManager: The exclusion manager for this pipeline.
|
|
183
|
+
"""
|
|
184
|
+
@property
|
|
185
|
+
def composer(self) -> Composer:
|
|
186
|
+
"""Get a Composer instance that manages this pipeline.
|
|
187
|
+
|
|
188
|
+
The Composer provides a fluent API for building pipelines by chaining
|
|
189
|
+
step-adding methods. It allows for easy composition of pipeline steps
|
|
190
|
+
in a readable, chainable manner.
|
|
191
|
+
|
|
192
|
+
Returns:
|
|
193
|
+
Composer: A composer instance that manages this pipeline.
|
|
194
|
+
"""
|
|
195
|
+
def clear(self) -> None:
|
|
196
|
+
"""Clears the pipeline by resetting steps, graph, and app to their initial state.
|
|
197
|
+
|
|
198
|
+
This method resets the pipeline to an empty state, clearing all steps and
|
|
199
|
+
invalidating any built graph or compiled app. Useful for reusing a pipeline
|
|
200
|
+
instance with different configurations.
|
|
201
|
+
"""
|
|
202
|
+
async def invoke(self, initial_state: PipelineState, config: dict[str, Any] | None = None) -> dict[str, Any]:
|
|
203
|
+
'''Runs the pipeline asynchronously with the given initial state and configuration.
|
|
204
|
+
|
|
205
|
+
Args:
|
|
206
|
+
initial_state (PipelineState): The initial state to start the pipeline with.
|
|
207
|
+
This initial state should comply with the state type of the pipeline.
|
|
208
|
+
config (dict[str, Any], optional): Additional configuration for the pipeline. User-defined config should not
|
|
209
|
+
have "langraph_" prefix as it should be reserved for internal use. Defaults to None.
|
|
210
|
+
|
|
211
|
+
Returns:
|
|
212
|
+
dict[str, Any]: The final state after the pipeline execution.
|
|
213
|
+
If \'debug_state\' is set to True in the config, the state logs will be included
|
|
214
|
+
in the final state with the key \'__state_logs__\'.
|
|
215
|
+
|
|
216
|
+
Raises:
|
|
217
|
+
BaseInvokerError: If an error occurs during LM invocation.
|
|
218
|
+
asyncio.CancelledError: If the execution is cancelled, preserved with added context.
|
|
219
|
+
TimeoutError: If the execution times out, preserved with added context.
|
|
220
|
+
RuntimeError: If an error occurs during pipeline execution. If the error is due to a step
|
|
221
|
+
execution, the step name will be included in the error message.
|
|
222
|
+
'''
|
|
223
|
+
def build_graph(self) -> None:
|
|
224
|
+
"""Builds the graph representation of the pipeline by connecting the steps."""
|
|
225
|
+
def get_mermaid_diagram(self) -> str:
|
|
226
|
+
"""Generate a Mermaid diagram representation of the pipeline.
|
|
227
|
+
|
|
228
|
+
Returns:
|
|
229
|
+
str: The complete Mermaid diagram representation.
|
|
230
|
+
"""
|
|
231
|
+
def __or__(self, other: Pipeline | BasePipelineStep) -> Pipeline:
|
|
232
|
+
"""Combines the current pipeline with another pipeline or step using the '|' operator.
|
|
233
|
+
|
|
234
|
+
When combining two pipelines, the state types must match.
|
|
235
|
+
|
|
236
|
+
Args:
|
|
237
|
+
other (Pipeline | BasePipelineStep): The other pipeline or step to combine with.
|
|
238
|
+
|
|
239
|
+
Returns:
|
|
240
|
+
Pipeline: A new pipeline consisting of the combined steps.
|
|
241
|
+
|
|
242
|
+
Raises:
|
|
243
|
+
ValueError: If the state types of the pipelines do not match.
|
|
244
|
+
"""
|
|
245
|
+
def __lshift__(self, other: Pipeline | BasePipelineStep) -> Pipeline:
|
|
246
|
+
"""Includes another pipeline or step using the '<<' operator.
|
|
247
|
+
|
|
248
|
+
This allows for easy composition where:
|
|
249
|
+
- If 'other' is a Pipeline: it becomes a subgraph within this pipeline
|
|
250
|
+
- If 'other' is a BasePipelineStep: it's added directly to this pipeline's steps
|
|
251
|
+
|
|
252
|
+
The syntax `pipeline1 << pipeline2` visually indicates pipeline2 being inserted into pipeline1.
|
|
253
|
+
The syntax `pipeline << step` adds the step to the pipeline.
|
|
254
|
+
|
|
255
|
+
Args:
|
|
256
|
+
other (Pipeline | BasePipelineStep): The pipeline to include as a subgraph or step to add.
|
|
257
|
+
|
|
258
|
+
Returns:
|
|
259
|
+
Pipeline: A new pipeline with the other pipeline included as a subgraph step or with the step added.
|
|
260
|
+
"""
|
|
261
|
+
def __rshift__(self, other: Pipeline | BasePipelineStep) -> Pipeline:
|
|
262
|
+
"""Includes this pipeline as a subgraph in another context using the '>>' operator.
|
|
263
|
+
|
|
264
|
+
This allows for easy composition where:
|
|
265
|
+
- If 'other' is a Pipeline: this pipeline becomes a subgraph within the other pipeline
|
|
266
|
+
- If 'other' is a BasePipelineStep: a new pipeline is created with the step, and this pipeline
|
|
267
|
+
is included as a subgraph within that pipeline
|
|
268
|
+
|
|
269
|
+
The syntax `pipeline1 >> pipeline2` embeds pipeline1 as a subgraph within pipeline2
|
|
270
|
+
(equivalent to pipeline2 << pipeline1).
|
|
271
|
+
The syntax `pipeline >> step` creates a new pipeline with the step, and includes this pipeline
|
|
272
|
+
as a subgraph within that pipeline.
|
|
273
|
+
|
|
274
|
+
Args:
|
|
275
|
+
other (Pipeline | BasePipelineStep): The pipeline to include this pipeline in as a subgraph,
|
|
276
|
+
or a step to create a new pipeline with.
|
|
277
|
+
|
|
278
|
+
Returns:
|
|
279
|
+
Pipeline: A new pipeline with this pipeline included as a subgraph.
|
|
280
|
+
"""
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
from _typeshed import Incomplete
|
|
2
|
+
from gllm_core.event.event_emitter import EventEmitter
|
|
3
|
+
from pydantic import BaseModel
|
|
4
|
+
from typing import Any, TypedDict
|
|
5
|
+
|
|
6
|
+
class RAGState(TypedDict):
|
|
7
|
+
'''A TypedDict representing the state of a Retrieval-Augmented Generation (RAG) pipeline.
|
|
8
|
+
|
|
9
|
+
This docstring documents the original intention of each of the attributes in the TypedDict.
|
|
10
|
+
However, in practice, the attributes may be modified or extended to suit the specific requirements of the
|
|
11
|
+
application. The TypedDict is used to enforce the structure of the state object.
|
|
12
|
+
|
|
13
|
+
Attributes:
|
|
14
|
+
user_query (str): The original query from the user.
|
|
15
|
+
queries (list[str]): A list of queries generated for retrieval.
|
|
16
|
+
retrieval_params (dict[str, Any]): Parameters used for the retrieval process.
|
|
17
|
+
chunks (list): A list of chunks retrieved from the knowledge base.
|
|
18
|
+
history (list[Any]): The history of the conversation or interaction.
|
|
19
|
+
context (str): The context information used for generating responses.
|
|
20
|
+
response_synthesis_bundle (dict[str, Any]): Data used for synthesizing the final response.
|
|
21
|
+
response (str): The generated response to the user\'s query.
|
|
22
|
+
references (str | list[str]): References or sources used in generating the response.
|
|
23
|
+
event_emitter (EventEmitter): An event emitter instance for logging purposes.
|
|
24
|
+
|
|
25
|
+
Example:
|
|
26
|
+
```python
|
|
27
|
+
state = {
|
|
28
|
+
"user_query": "What is machine learning?",
|
|
29
|
+
"queries": ["machine learning definition", "ML basics"],
|
|
30
|
+
"retrieval_params": {"top_k": 5, "threshold": 0.8},
|
|
31
|
+
"chunks": [
|
|
32
|
+
{"content": "Machine learning is...", "score": 0.95},
|
|
33
|
+
{"content": "ML algorithms include...", "score": 0.87}
|
|
34
|
+
],
|
|
35
|
+
"history": [
|
|
36
|
+
{"role": "user", "contents": ["What is machine learning?"]},
|
|
37
|
+
{"role": "assistant", "contents": ["Machine learning is a subset of artificial intelligence..."]}
|
|
38
|
+
],
|
|
39
|
+
"context": "Retrieved information about ML",
|
|
40
|
+
"response_synthesis_bundle": {"template": "informative"},
|
|
41
|
+
"response": "Machine learning is a subset of artificial intelligence...",
|
|
42
|
+
"references": ["source1.pdf", "article2.html"],
|
|
43
|
+
"event_emitter": EventEmitter()
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
'''
|
|
47
|
+
user_query: str
|
|
48
|
+
queries: list[str]
|
|
49
|
+
retrieval_params: dict[str, Any]
|
|
50
|
+
chunks: list[Any]
|
|
51
|
+
history: list[Any]
|
|
52
|
+
context: str
|
|
53
|
+
response_synthesis_bundle: dict[str, Any]
|
|
54
|
+
response: str
|
|
55
|
+
references: str | list[str]
|
|
56
|
+
event_emitter: EventEmitter
|
|
57
|
+
|
|
58
|
+
class RAGStateModel(BaseModel):
|
|
59
|
+
'''A Pydantic BaseModel representing the state of a Retrieval-Augmented Generation (RAG) pipeline.
|
|
60
|
+
|
|
61
|
+
This implementation provides runtime validation, default values, and enhanced type safety
|
|
62
|
+
compared to the TypedDict version. It maintains compatibility with LangGraph while offering
|
|
63
|
+
improved developer experience through automatic validation and sensible defaults.
|
|
64
|
+
|
|
65
|
+
Attributes:
|
|
66
|
+
user_query (str): The original query from the user.
|
|
67
|
+
queries (list[str]): A list of queries generated for retrieval. Defaults to empty list.
|
|
68
|
+
retrieval_params (dict[str, Any]): Parameters used for the retrieval process. Defaults to empty dict.
|
|
69
|
+
chunks (list[Any]): A list of chunks retrieved from the knowledge base. Defaults to empty list.
|
|
70
|
+
history (list[Any]): The history of the conversation or interaction. Defaults to empty list.
|
|
71
|
+
context (str): The context information used for generating responses. Defaults to empty string.
|
|
72
|
+
response_synthesis_bundle (dict[str, Any]): Data used for synthesizing the final response.
|
|
73
|
+
Defaults to empty dict.
|
|
74
|
+
response (str): The generated response to the user\'s query. Defaults to empty string.
|
|
75
|
+
references (str | list[str]): References or sources used in generating the response.
|
|
76
|
+
Defaults to empty list.
|
|
77
|
+
event_emitter (EventEmitter | None): An event emitter instance for logging purposes. Defaults to None.
|
|
78
|
+
|
|
79
|
+
Example:
|
|
80
|
+
```python
|
|
81
|
+
# Basic usage with minimal required fields
|
|
82
|
+
state = RAGStateModel(user_query="What is machine learning?")
|
|
83
|
+
|
|
84
|
+
# Full usage with all fields
|
|
85
|
+
state = RAGStateModel(
|
|
86
|
+
user_query="What is machine learning?",
|
|
87
|
+
queries=["machine learning definition", "ML basics"],
|
|
88
|
+
retrieval_params={"top_k": 5, "threshold": 0.8},
|
|
89
|
+
chunks=[
|
|
90
|
+
{"content": "Machine learning is...", "score": 0.95},
|
|
91
|
+
{"content": "ML algorithms include...", "score": 0.87}
|
|
92
|
+
],
|
|
93
|
+
history=[
|
|
94
|
+
{"role": "user", "contents": ["What is machine learning?"]},
|
|
95
|
+
{"role": "assistant", "contents": ["Machine learning is a subset of artificial intelligence..."]}
|
|
96
|
+
],
|
|
97
|
+
context="Retrieved information about ML",
|
|
98
|
+
response_synthesis_bundle={"template": "informative"},
|
|
99
|
+
response="Machine learning is a subset of artificial intelligence...",
|
|
100
|
+
references=["source1.pdf", "article2.html"],
|
|
101
|
+
event_emitter=EventEmitter()
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
# Convert to dictionary for pipeline processing
|
|
105
|
+
state_dict = state.model_dump()
|
|
106
|
+
|
|
107
|
+
# Use with json_encoders for special types
|
|
108
|
+
state_json = state.model_dump_json()
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Example with custom JSON encoders:
|
|
112
|
+
```python
|
|
113
|
+
from datetime import datetime
|
|
114
|
+
from pydantic import BaseModel, Field
|
|
115
|
+
|
|
116
|
+
class CustomStateModel(BaseModel):
|
|
117
|
+
timestamp: datetime = Field(default_factory=datetime.now)
|
|
118
|
+
|
|
119
|
+
class Config:
|
|
120
|
+
json_encoders = {
|
|
121
|
+
datetime: lambda v: v.isoformat(),
|
|
122
|
+
EventEmitter: lambda v: str(v) if v else None
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
'''
|
|
126
|
+
user_query: str
|
|
127
|
+
queries: list[str]
|
|
128
|
+
retrieval_params: dict[str, Any]
|
|
129
|
+
chunks: list[Any]
|
|
130
|
+
history: list[Any]
|
|
131
|
+
context: str
|
|
132
|
+
response_synthesis_bundle: dict[str, Any]
|
|
133
|
+
response: str
|
|
134
|
+
references: str | list[str]
|
|
135
|
+
event_emitter: EventEmitter | None
|
|
136
|
+
class Config:
|
|
137
|
+
"""Pydantic configuration."""
|
|
138
|
+
arbitrary_types_allowed: bool
|
|
139
|
+
json_encoders: Incomplete
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
from gllm_pipeline.router.aurelio_semantic_router import AurelioSemanticRouter as AurelioSemanticRouter
|
|
2
|
+
from gllm_pipeline.router.lm_based_router import LMBasedRouter as LMBasedRouter
|
|
3
|
+
from gllm_pipeline.router.rule_based_router import RuleBasedRouter as RuleBasedRouter
|
|
4
|
+
from gllm_pipeline.router.similarity_based_router import SimilarityBasedRouter as SimilarityBasedRouter
|
|
5
|
+
|
|
6
|
+
__all__ = ['AurelioSemanticRouter', 'LMBasedRouter', 'RuleBasedRouter', 'SimilarityBasedRouter']
|