-
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 164ffde
Showing
56 changed files
with
335 additions
and
453 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,39 @@ | ||
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 .image_artifact import ImageArtifact | ||
from .audio_artifact import AudioArtifact | ||
|
||
from .action_artifact import ActionArtifact | ||
|
||
from .generic_artifact import GenericArtifact | ||
|
||
|
||
__all__ = [ | ||
"BaseArtifact", | ||
"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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,20 @@ | ||
from __future__ import annotations | ||
|
||
from attrs import define | ||
from attrs import define, field | ||
|
||
from griptape.artifacts import MediaArtifact | ||
from griptape.artifacts import BaseArtifact | ||
|
||
|
||
@define | ||
class AudioArtifact(MediaArtifact): | ||
"""AudioArtifact is a type of MediaArtifact representing audio.""" | ||
class AudioArtifact(BaseArtifact): | ||
"""AudioArtifact is a type of Artifact representing audio.""" | ||
|
||
media_type: str = "audio" | ||
value: bytes = field(metadata={"serializable": True}) | ||
format: str = field(kw_only=True, metadata={"serializable": True}) | ||
|
||
@property | ||
def mime_type(self) -> str: | ||
return f"audio/{self.format}" | ||
|
||
def to_text(self) -> str: | ||
return f"Audio, format: {self.format}, 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
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,10 @@ | ||
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/octet-stream", 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,35 @@ | ||
from __future__ import annotations | ||
|
||
import base64 | ||
|
||
from attrs import define, field | ||
|
||
from griptape.artifacts import MediaArtifact | ||
from griptape.artifacts import BaseArtifact | ||
|
||
|
||
@define | ||
class ImageArtifact(MediaArtifact): | ||
"""ImageArtifact is a type of MediaArtifact representing an image. | ||
class ImageArtifact(BaseArtifact): | ||
"""ImageArtifact is a type of Artifact representing an image. | ||
Attributes: | ||
value: Raw bytes representing media data. | ||
media_type: The type of media, defaults to "image". | ||
format: The format of the media, like png, jpeg, or gif. | ||
name: Artifact name, generated using creation time and a random string. | ||
model: Optionally specify the model used to generate the media. | ||
prompt: Optionally specify the prompt used to generate the media. | ||
format: The format of the media, like png, jpeg, or gif. Default is png. | ||
width: The width of the image in pixels. | ||
height: The height of the image in pixels. | ||
""" | ||
|
||
media_type: str = "image" | ||
value: bytes = field(metadata={"serializable": True}) | ||
format: str = field(default="png", kw_only=True, metadata={"serializable": True}) | ||
width: int = field(kw_only=True, metadata={"serializable": True}) | ||
height: int = field(kw_only=True, metadata={"serializable": True}) | ||
|
||
@property | ||
def base64(self) -> str: | ||
return base64.b64encode(self.value).decode("utf-8") | ||
|
||
@property | ||
def mime_type(self) -> str: | ||
return f"image/{self.format}" | ||
|
||
def to_text(self) -> str: | ||
return self.base64 |
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.