Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
vachillo committed Aug 12, 2024
1 parent 5dd0bc5 commit 9110e98
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 140 deletions.
2 changes: 0 additions & 2 deletions griptape/artifacts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from .action_artifact import ActionArtifact
from .generic_artifact import GenericArtifact
from .control_flow_artifact import ControlFlowArtifact
from .task_artifact import TaskArtifact


__all__ = [
Expand All @@ -30,5 +29,4 @@
"ActionArtifact",
"GenericArtifact",
"ControlFlowArtifact",
"TaskArtifact",
]
9 changes: 4 additions & 5 deletions griptape/artifacts/boolean_artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@
from typing import Union

from attrs import define, field
from griptape.artifacts import TextArtifact, BaseArtifact

from griptape.artifacts import BaseArtifact, TextArtifact


@define
class BooleanArtifact(BaseArtifact):
value: bool = field(converter=bool, metadata={"serializable": True})

@classmethod
def parse_bool(cls, value: Union[str, bool, TextArtifact]) -> BooleanArtifact:
"""
Convert a string literal or bool to a BooleanArtifact. The string must be either "true" or "false" with any casing.
"""
def parse_bool(cls, value: Union[str, bool, TextArtifact]) -> BooleanArtifact: # noqa: FBT001
"""Convert a string literal, TextArtifact or bool to a BooleanArtifact. The string must be either "true" or "false" with any casing."""
if value is not None:
if isinstance(value, TextArtifact):
value = str(value)
Expand Down
1 change: 1 addition & 0 deletions griptape/artifacts/control_flow_artifact.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from attrs import define

from griptape.artifacts import BaseArtifact


Expand Down
30 changes: 0 additions & 30 deletions griptape/artifacts/task_artifact.py

This file was deleted.

3 changes: 1 addition & 2 deletions griptape/memory/meta/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from .base_meta_entry import BaseMetaEntry
from .action_subtask_meta_entry import ActionSubtaskMetaEntry
from .control_flow_meta_entry import ControlFlowMetaEntry
from .meta_memory import MetaMemory

__all__ = ["BaseMetaEntry", "MetaMemory", "ActionSubtaskMetaEntry", "ControlFlowMetaEntry"]
__all__ = ["BaseMetaEntry", "MetaMemory", "ActionSubtaskMetaEntry"]
15 changes: 0 additions & 15 deletions griptape/memory/meta/control_flow_meta_entry.py

This file was deleted.

16 changes: 5 additions & 11 deletions griptape/tasks/base_control_flow_task.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
from __future__ import annotations

from abc import ABC

from attrs import define

from griptape.tasks import BaseTask
from griptape.memory.meta import ControlFlowMetaEntry


@define
class BaseControlFlowTask(BaseTask, ABC):
def before_run(self) -> None:
super().before_run()

self.structure.logger.info(f"{self.__class__.__name__} {self.id}\nInput: {self.input.to_text()}")
self.structure.logger.info("%s %s\nInput: %s", self.__class__.__name__, self.id, self.input.to_text())

def after_run(self) -> None:
super().after_run()

self.structure.meta_memory.add_entry(
ControlFlowMetaEntry(
input_tasks=[parent.id for parent in self.parents],
output_tasks=[child.id for child in filter(lambda child: not child.is_finished(), self.children)],
output=self.output,
)
)

self.structure.logger.info(f"{self.__class__.__name__} {self.id}\nOutput: {self.output.to_text()}")
self.structure.logger.info("%s %s\nOutput: %s", self.__class__.__name__, self.id, self.output.to_text())

def _cancel_children_rec(self, task: BaseTask, chosen_task: BaseTask) -> None:
for child in filter(lambda child: child != chosen_task, task.children):
Expand Down
45 changes: 0 additions & 45 deletions griptape/tasks/boolean_control_flow_task.py

This file was deleted.

31 changes: 14 additions & 17 deletions griptape/tasks/choice_control_flow_task.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from __future__ import annotations

from typing import Callable

from attrs import define, field

from griptape.artifacts import BaseArtifact, ErrorArtifact, TaskArtifact, ListArtifact
from griptape.tasks import BaseTask
from griptape.tasks import BaseControlFlowTask
from griptape.artifacts import BaseArtifact, ErrorArtifact, ListArtifact, TextArtifact
from griptape.tasks import BaseControlFlowTask, BaseTask


@define
Expand All @@ -16,18 +17,14 @@ class ChoiceControlFlowTask(BaseControlFlowTask):
@property
def input(self) -> BaseArtifact:
if len(self.parents) == 1:
return TaskArtifact(self.parents[0])
return ListArtifact([TaskArtifact(parent) for parent in self.parents])

def before_run(self) -> None:
super().before_run()

self.structure.logger.info(f"{self.__class__.__name__} {self.id}\nInput: {self.input.to_text()}")

def after_run(self) -> None:
super().after_run()

self.structure.logger.info(f"{self.__class__.__name__} {self.id}\nOutput: {self.output.to_text()}")
return self.parents[0].output if self.parents[0].output is not None else TextArtifact("")
parents = filter(lambda parent: parent.output is not None, self.parents)
return ListArtifact(
[
parent.output
for parent in parents # pyright: ignore[reportArgumentType]
]
)

def run(self) -> BaseArtifact:
tasks = self.control_flow_fn(
Expand All @@ -54,11 +51,11 @@ def run(self) -> BaseArtifact:
[
parent.value.output
for parent in filter(lambda parent: parent.value.output is not None, self.input.value)
] # pyright: ignore
]
)
if isinstance(self.input, ListArtifact)
else self.input.value.output
)
self._cancel_children_rec(self, task)

return self.output # pyright: ignore
return self.output # pyright: ignore[reportReturnType]
14 changes: 1 addition & 13 deletions tests/unit/structures/test_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,12 @@

import pytest

from pytest import fixture
from griptape.memory.task.storage import TextArtifactStorage
from tests.mocks.mock_prompt_driver import MockPromptDriver
from griptape.rules import Rule, Ruleset
from griptape.tasks import PromptTask, BaseTask, ToolkitTask, CodeExecutionTask, ChoiceControlFlowTask
from griptape.structures import Workflow
from griptape.artifacts import ErrorArtifact, TextArtifact
from griptape.memory.structure import ConversationMemory
from griptape.memory.task.storage import TextArtifactStorage
from griptape.rules import Rule, Ruleset
from griptape.structures import Workflow
from griptape.tasks import BaseTask, CodeExecutionTask, PromptTask, ToolkitTask
from griptape.tasks import BaseTask, ChoiceControlFlowTask, CodeExecutionTask, PromptTask, ToolkitTask
from tests.mocks.mock_embedding_driver import MockEmbeddingDriver
from tests.mocks.mock_prompt_driver import MockPromptDriver
from tests.mocks.mock_tool.tool import MockTool
Expand Down Expand Up @@ -48,9 +42,6 @@ def test_workflow_with_control_flow_task(self):
workflow = Workflow(prompt_driver=MockPromptDriver(), tasks=[task1, task2, task3, task4, control_flow_task])
workflow.resolve_relationships()
workflow.run()
from griptape.utils import StructureVisualizer

print(StructureVisualizer(workflow).to_url())

assert task1.state == BaseTask.State.FINISHED
assert task2.state == BaseTask.State.FINISHED
Expand Down Expand Up @@ -81,9 +72,6 @@ def test_workflow_with_multiple_control_flow_tasks(self):
)
workflow.resolve_relationships()
workflow.run()
from griptape.utils import StructureVisualizer

print(StructureVisualizer(workflow).to_url())

assert task1.state == BaseTask.State.FINISHED
assert task2.state == BaseTask.State.CANCELLED
Expand Down

0 comments on commit 9110e98

Please sign in to comment.