mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-11 00:58:30 +00:00
WIP.
This commit is contained in:
@@ -1,22 +1,19 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import Any, Callable, Dict, List, Tuple, Union
|
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
|
||||||
|
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
from crewai.crew import Crew
|
from crewai.crew import Crew
|
||||||
|
from crewai.pipeline.pipeline import Pipeline
|
||||||
|
|
||||||
|
|
||||||
class PipelineRouter(BaseModel):
|
class PipelineRouter(BaseModel):
|
||||||
conditions: List[
|
conditions: List[Tuple[Callable[[Dict[str, Any]], bool], Pipeline]] = []
|
||||||
Tuple[Callable[[Dict[str, Any]], bool], Union[Crew, "Pipeline"]]
|
default: Optional[Pipeline] = None
|
||||||
] = []
|
|
||||||
default: Union[Crew, "Pipeline", None] = None
|
|
||||||
|
|
||||||
def add_condition(
|
def add_condition(
|
||||||
self,
|
self, condition: Callable[[Dict[str, Any]], bool], next_stage: Pipeline
|
||||||
condition: Callable[[Dict[str, Any]], bool],
|
|
||||||
next_stage: Union[Crew, "Pipeline"],
|
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Add a condition and its corresponding next stage to the router.
|
Add a condition and its corresponding next stage to the router.
|
||||||
@@ -55,9 +52,7 @@ class PipelineRouter(BaseModel):
|
|||||||
|
|
||||||
raise ValueError("No conditions were met and no default stage was set.")
|
raise ValueError("No conditions were met and no default stage was set.")
|
||||||
|
|
||||||
def _update_trace(
|
def _update_trace(self, input_dict: Dict[str, Any], next_stage: Pipeline):
|
||||||
self, input_dict: Dict[str, Any], next_stage: Union[Crew, "Pipeline"]
|
|
||||||
):
|
|
||||||
"""Update the trace to show that the input went through the router."""
|
"""Update the trace to show that the input went through the router."""
|
||||||
if "trace" not in input_dict:
|
if "trace" not in input_dict:
|
||||||
input_dict["trace"] = []
|
input_dict["trace"] = []
|
||||||
@@ -67,10 +62,3 @@ class PipelineRouter(BaseModel):
|
|||||||
"next_stage": next_stage.__class__.__name__,
|
"next_stage": next_stage.__class__.__name__,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# TODO: See if this is necessary
|
|
||||||
from crewai.pipeline.pipeline import Pipeline
|
|
||||||
|
|
||||||
# This line should be at the end of the file
|
|
||||||
PipelineRouter.model_rebuild()
|
|
||||||
|
|||||||
Reference in New Issue
Block a user