diff options
| author | 2024-03-04 17:54:47 +0800 | |
|---|---|---|
| committer | 2024-03-04 17:54:47 +0800 | |
| commit | edf6101277450d9b849f329cdfe27ad204c84392 (patch) | |
| tree | 1a76ac5dc771acb8be631412936110ebb1ad2e3a | |
| parent | 83d35b5e6650e6d077cac35b20e5835feefc7331 (diff) | |
| download | infini-edf6101277450d9b849f329cdfe27ad204c84392.tar.gz infini-edf6101277450d9b849f329cdfe27ad204c84392.zip | |
feat(workflow): supports blocked workflow
| -rw-r--r-- | src/infini/core.py | 35 | ||||
| -rw-r--r-- | src/infini/input.py | 3 | ||||
| -rw-r--r-- | src/infini/output.py | 5 |
3 files changed, 30 insertions, 13 deletions
diff --git a/src/infini/core.py b/src/infini/core.py index 7c84a15f..0de6034c 100644 --- a/src/infini/core.py +++ b/src/infini/core.py @@ -15,9 +15,7 @@ class Core: interceptor: Interceptor injector: Injector - def input( - self, input: Input - ) -> GeneratorT[Union[str, Output], Any, None]: + def input(self, input: Input) -> GeneratorT[Union[str, Output], Any, None]: for pre_intercepted_stream in self.pre_intercept(input): if isinstance(pre_intercepted_stream, Output): if not isinstance(pre_intercepted_stream, Output): @@ -26,7 +24,15 @@ class Core: ) if pre_intercepted_stream.is_empty(): return - yield self.generate(pre_intercepted_stream) + if pre_intercepted_stream.type == "workflow": + yield pre_intercepted_stream + if pre_intercepted_stream.block: + while pre_intercepted_stream.status != 0: + pass + continue + else: + yield self.generate(pre_intercepted_stream) # TODO 拦截拦截器文本 + if pre_intercepted_stream.block: return else: @@ -39,14 +45,27 @@ class Core: ) if handled_stream.is_empty(): return - outcome = self.generate(handled_stream) + if handled_stream.type == "workflow": + yield handled_stream + if handled_stream.block: + while handled_stream.status != 0: + pass + continue + else: + outcome = self.generate(handled_stream) for stream in self.intercept(handled_stream, outcome): if isinstance(stream, Output): if stream.is_empty(): return - yield self.generate(stream) - if stream.block: - return + if stream.type == "workflow": + yield stream + if stream.block: + while stream.status != 0: + pass + else: + yield self.generate(stream) + if stream.block: + return continue outcome = stream yield outcome diff --git a/src/infini/input.py b/src/infini/input.py index 30683a4b..0bbb3f2f 100644 --- a/src/infini/input.py +++ b/src/infini/input.py @@ -32,10 +32,9 @@ class Input(Generic[T]): type: Literal["text", "workflow"], name: str, *, - status: int = 0, block: bool = False, variables: Dict[str, Any] = {}, ): vars = self.variables.copy() vars.update(variables) - return Output(type, name, status=status, block=block, variables=vars) + return Output(type, name, block=block, variables=vars) diff --git a/src/infini/output.py b/src/infini/output.py index 13f26d47..6520d9b4 100644 --- a/src/infini/output.py +++ b/src/infini/output.py @@ -14,19 +14,18 @@ class Output: type: Union[Literal["null", "text", "workflow"], str], name: str, *, - status: int = 0, block: bool = False, variables: Dict[str, Any] = {}, ) -> None: self.type = type self.name = name - self.status = status + self.status = 1 self.block = block self.variables = variables @classmethod def empty(cls) -> "Output": - return cls("null", "null", status=0, block=True) + return cls("null", "null", block=True) def is_empty(self) -> bool: return self.type == "null" |
