-
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 57011f0
Showing
48 changed files
with
300 additions
and
395 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,35 @@ | ||
from .base_artifact import BaseArtifact | ||
from .base_system_artifact import BaseSystemArtifact | ||
from .base_media_artifact import BaseMediaArtifact | ||
|
||
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 .list_artifact import ListArtifact | ||
from .media_artifact import MediaArtifact | ||
from .image_artifact import ImageArtifact | ||
from .audio_artifact import AudioArtifact | ||
from .action_artifact import ActionArtifact | ||
from .generic_artifact import GenericArtifact | ||
from .table_artifact import TableArtifact | ||
|
||
|
||
__all__ = [ | ||
"BaseArtifact", | ||
"BaseSystemArtifact", | ||
"BaseMediaArtifact", | ||
"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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
from __future__ import annotations | ||
|
||
from attrs import define | ||
from attrs import define, field | ||
|
||
from griptape.artifacts import MediaArtifact | ||
from griptape.artifacts import BaseMediaArtifact | ||
|
||
|
||
@define | ||
class AudioArtifact(MediaArtifact): | ||
"""AudioArtifact is a type of MediaArtifact representing audio.""" | ||
class AudioArtifact(BaseMediaArtifact): | ||
"""AudioArtifact is a type of Media Artifact representing audio.""" | ||
|
||
media_type: str = "audio" | ||
media_type: str = field(default="audio", kw_only=True, metadata={"serializable": True}) |
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,33 @@ | ||
from __future__ import annotations | ||
|
||
import base64 | ||
|
||
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}" | ||
|
||
@property | ||
def base64(self) -> str: | ||
return base64.b64encode(self.value).decode("utf-8") | ||
|
||
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,7 @@ | ||
from griptape.artifacts import BaseArtifact | ||
|
||
|
||
class BaseSystemArtifact(BaseArtifact): | ||
"""Base class for Artifacts specific to Griptape.""" | ||
|
||
... |
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,27 @@ | ||
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 | ||
@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] | ||
|
||
|
||
@define | ||
class JsonArtifact(BaseArtifact): | ||
value: Json = field(converter=lambda v: json.loads(json.dumps(v)), metadata={"serializable": True}) | ||
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.