-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ef61c53
commit 9f6898f
Showing
53 changed files
with
325 additions
and
403 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,41 @@ | ||
from .base_artifact import BaseArtifact | ||
|
||
from .base_system_artifact import BaseSystemArtifact | ||
from .error_artifact import ErrorArtifact | ||
from .info_artifact import InfoArtifact | ||
|
||
from .text_artifact import TextArtifact | ||
from .json_artifact import JsonArtifact | ||
from .blob_artifact import BlobArtifact | ||
from .boolean_artifact import BooleanArtifact | ||
from .csv_row_artifact import CsvRowArtifact | ||
from .table_artifact import TableArtifact | ||
|
||
from .list_artifact import ListArtifact | ||
from .media_artifact import MediaArtifact | ||
|
||
from .blob_artifact import BlobArtifact | ||
|
||
from .base_media_artifact import BaseMediaArtifact | ||
from .image_artifact import ImageArtifact | ||
from .audio_artifact import AudioArtifact | ||
|
||
from .action_artifact import ActionArtifact | ||
|
||
from .generic_artifact import GenericArtifact | ||
|
||
|
||
__all__ = [ | ||
"BaseArtifact", | ||
"BaseMediaArtifact", | ||
"BaseSystemArtifact", | ||
"ErrorArtifact", | ||
"InfoArtifact", | ||
"TextArtifact", | ||
"JsonArtifact", | ||
"BlobArtifact", | ||
"BooleanArtifact", | ||
"CsvRowArtifact", | ||
"ListArtifact", | ||
"MediaArtifact", | ||
"ImageArtifact", | ||
"AudioArtifact", | ||
"ActionArtifact", | ||
"GenericArtifact", | ||
"TableArtifact", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from __future__ import annotations | ||
|
||
from attrs import define, field | ||
|
||
from griptape.artifacts import BaseArtifact | ||
|
||
|
||
@define | ||
class BaseMediaArtifact(BaseArtifact): | ||
"""BaseMediaArtifact is a type of Artifact that represents media (image, audio, video, etc.) and can be extended to support a specific media type. | ||
Attributes: | ||
value: Raw bytes representing media data. | ||
media_type: Main type of an IANA media type, such as "text", "audio", or "image". | ||
format: Subtype of an IANA media type, such as "plain", "mp3", or "jpeg". | ||
""" | ||
|
||
value: bytes = field(metadata={"serializable": True}) | ||
media_type: str = field(kw_only=True, metadata={"serializable": True}) | ||
format: str = field(kw_only=True, metadata={"serializable": True}) | ||
|
||
@property | ||
def mime_type(self) -> str: | ||
return f"{self.media_type}/{self.format}" | ||
|
||
def to_text(self) -> str: | ||
return f"Media, type: {self.mime_type}, size: {len(self.value)} bytes" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from abc import ABC | ||
|
||
from griptape.artifacts import BaseArtifact | ||
|
||
|
||
class BaseSystemArtifact(BaseArtifact, ABC): | ||
"""Base class for Artifacts specific to Griptape.""" | ||
|
||
... | ||
|
||
def to_text(self) -> str: | ||
return self.value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,28 @@ | ||
from __future__ import annotations | ||
|
||
import os.path | ||
from typing import Optional | ||
from typing import Any | ||
|
||
from attrs import define, field | ||
from attrs import Converter, define, field | ||
|
||
from griptape.artifacts import BaseArtifact | ||
|
||
|
||
@define | ||
class BlobArtifact(BaseArtifact): | ||
value: bytes = field(converter=BaseArtifact.value_to_bytes, metadata={"serializable": True}) | ||
dir_name: Optional[str] = field(default=None, kw_only=True, metadata={"serializable": True}) | ||
value: bytes = field( | ||
converter=Converter(lambda value: BlobArtifact.value_to_bytes(value)), | ||
metadata={"serializable": True}, | ||
) | ||
encoding: str = field(default="utf-8", kw_only=True) | ||
encoding_error_handler: str = field(default="strict", kw_only=True) | ||
|
||
def __add__(self, other: BaseArtifact) -> BlobArtifact: | ||
return BlobArtifact(self.value + other.value, name=self.name) | ||
|
||
@property | ||
def full_path(self) -> str: | ||
return os.path.join(self.dir_name, self.name) if self.dir_name else self.name | ||
media_type: str = field(default="application", kw_only=True) | ||
|
||
@classmethod | ||
def value_to_bytes(cls, value: Any) -> bytes: | ||
if isinstance(value, bytes): | ||
return value | ||
else: | ||
return str(value).encode() | ||
|
||
def to_text(self) -> str: | ||
return self.value.decode(encoding=self.encoding, errors=self.encoding_error_handler) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,24 @@ | ||
from __future__ import annotations | ||
|
||
import json | ||
from typing import Union | ||
from typing import Any, Union | ||
|
||
from attrs import define, field | ||
from attrs import Converter, define, field | ||
|
||
from griptape.artifacts import BaseArtifact | ||
|
||
Json = Union[dict[str, "Json"], list["Json"], str, int, float, bool, None] | ||
from griptape.artifacts.text_artifact import TextArtifact | ||
|
||
|
||
@define | ||
class JsonArtifact(BaseArtifact): | ||
value: Json = field(converter=lambda v: json.loads(json.dumps(v)), metadata={"serializable": True}) | ||
class JsonArtifact(TextArtifact): | ||
Json = Union[dict[str, "Json"], list["Json"], str, int, float, bool, None] | ||
|
||
value: Json = field( | ||
converter=Converter(lambda value: JsonArtifact.value_to_dict(value)), metadata={"serializable": True} | ||
) | ||
|
||
@classmethod | ||
def value_to_dict(cls, value: Any) -> dict: | ||
return json.loads(json.dumps(value)) | ||
|
||
def to_text(self) -> str: | ||
return json.dumps(self.value) | ||
|
||
def __add__(self, other: BaseArtifact) -> JsonArtifact: | ||
raise NotImplementedError |
Oops, something went wrong.