From e16d23b35714fa8cb3a24983b95661837c5fa4bd Mon Sep 17 00:00:00 2001 From: Collin Dutter Date: Fri, 27 Sep 2024 15:45:13 -0700 Subject: [PATCH] Add Workflow.outputs (#1208) --- CHANGELOG.md | 7 +++---- griptape/structures/workflow.py | 5 +++++ tests/unit/structures/test_workflow.py | 9 +++++++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index db6d0aaac..31a2b3b5a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,14 +5,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## Unreleased -### Added -- `Workflow.input_tasks` and `Workflow.output_tasks` to access the input and output tasks of a Workflow. -- Ability to pass nested list of `Tasks` to `Structure.tasks` allowing for more complex declarative Structure definitions. - ## Added +- `Workflow.input_tasks` and `Workflow.output_tasks` to access the input and output tasks of a Workflow. +- Ability to pass nested list of `Tasks` to `Structure.tasks` allowing for more complex declarative Structure definitions. - Parameter `pipeline_task` on `HuggingFacePipelinePromptDriver` for creating different types of `Pipeline`s. - `TavilyWebSearchDriver` to integrate Tavily's web search capabilities. +- `Workflow.outputs` to access the outputs of a Workflow. ### Changed - **BREAKING**: Renamed parameters on several classes to `client`: diff --git a/griptape/structures/workflow.py b/griptape/structures/workflow.py index 5a3935d5b..982ccb5f6 100644 --- a/griptape/structures/workflow.py +++ b/griptape/structures/workflow.py @@ -12,6 +12,7 @@ from griptape.structures import Structure if TYPE_CHECKING: + from griptape.artifacts import BaseArtifact from griptape.tasks import BaseTask @@ -33,6 +34,10 @@ def input_tasks(self) -> list[BaseTask]: def output_tasks(self) -> list[BaseTask]: return [task for task in self.tasks if not task.children] + @property + def outputs(self) -> list[BaseArtifact]: + return [task.output.value for task in self.output_tasks if task.output is not None] + def add_task(self, task: BaseTask) -> BaseTask: if (existing_task := self.try_find_task(task.id)) is not None: return existing_task diff --git a/tests/unit/structures/test_workflow.py b/tests/unit/structures/test_workflow.py index de9d270d5..130b8a426 100644 --- a/tests/unit/structures/test_workflow.py +++ b/tests/unit/structures/test_workflow.py @@ -826,6 +826,15 @@ def test_input_tasks(self): assert workflow.input_tasks == [parent] + def test_outputs(self): + workflow = Workflow(tasks=[PromptTask("parent") for _ in range(3)]) + + assert workflow.outputs == [] + + workflow.run() + + assert workflow.outputs == ["mock output"] * 3 + @staticmethod def _validate_topology_1(workflow) -> None: assert len(workflow.tasks) == 4