From b51840c12dc027984ab45edfb057b393f0e0196d Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 29 Nov 2024 11:04:22 -0800 Subject: [PATCH] [REMOVE ARTIFACTS FROM SWARMS.ARTIFACTS] --- requirements.txt | 2 +- swarms/artifacts/__init__.py | 5 +- swarms/artifacts/base_artifact.py | 77 ------------------------------- swarms/artifacts/text_artifact.py | 58 ----------------------- 4 files changed, 2 insertions(+), 140 deletions(-) delete mode 100644 swarms/artifacts/base_artifact.py delete mode 100644 swarms/artifacts/text_artifact.py diff --git a/requirements.txt b/requirements.txt index ca9fdcdd..e5375a0d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,7 +5,7 @@ asyncio>=3.4.3,<4.0 toml pypdf==4.3.1 ratelimit==2.2.1 -loguru==0.7.2 +loguru pydantic==2.8.2 tenacity rich diff --git a/swarms/artifacts/__init__.py b/swarms/artifacts/__init__.py index 448d6101..d52375b4 100644 --- a/swarms/artifacts/__init__.py +++ b/swarms/artifacts/__init__.py @@ -1,9 +1,6 @@ -from swarms.artifacts.base_artifact import BaseArtifact -from swarms.artifacts.text_artifact import TextArtifact + from swarms.artifacts.main_artifact import Artifact __all__ = [ - "BaseArtifact", - "TextArtifact", "Artifact", ] diff --git a/swarms/artifacts/base_artifact.py b/swarms/artifacts/base_artifact.py deleted file mode 100644 index aad07a7b..00000000 --- a/swarms/artifacts/base_artifact.py +++ /dev/null @@ -1,77 +0,0 @@ -from __future__ import annotations - -import json -import uuid -from abc import ABC, abstractmethod -from dataclasses import dataclass -from typing import Any - - -@dataclass -class BaseArtifact(ABC): - """ - Base class for artifacts. - """ - - id: str - name: str - value: Any - - def __post_init__(self): - if self.id is None: - self.id = uuid.uuid4().hex - if self.name is None: - self.name = self.id - - @classmethod - def value_to_bytes(cls, value: Any) -> bytes: - """ - Convert the value to bytes. - """ - if isinstance(value, bytes): - return value - else: - return str(value).encode() - - @classmethod - def value_to_dict(cls, value: Any) -> dict: - """ - Convert the value to a dictionary. - """ - if isinstance(value, dict): - dict_value = value - else: - dict_value = json.loads(value) - - return {k: v for k, v in dict_value.items()} - - def to_text(self) -> str: - """ - Convert the value to text. - """ - return str(self.value) - - def __str__(self) -> str: - """ - Return a string representation of the artifact. - """ - return self.to_text() - - def __bool__(self) -> bool: - """ - Return the boolean value of the artifact. - """ - return bool(self.value) - - def __len__(self) -> int: - """ - Return the length of the artifact. - """ - return len(self.value) - - @abstractmethod - def __add__(self, other: BaseArtifact) -> BaseArtifact: - """ - Add two artifacts together. - """ - ... diff --git a/swarms/artifacts/text_artifact.py b/swarms/artifacts/text_artifact.py deleted file mode 100644 index 13ca4dfd..00000000 --- a/swarms/artifacts/text_artifact.py +++ /dev/null @@ -1,58 +0,0 @@ -from __future__ import annotations - -from dataclasses import dataclass, field -from typing import Callable -from swarms.artifacts.base_artifact import BaseArtifact - - -@dataclass -class TextArtifact(BaseArtifact): - """ - Represents a text artifact. - - Attributes: - value (str): The text value of the artifact. - encoding (str, optional): The encoding of the text (default is "utf-8"). - encoding_error_handler (str, optional): The error handler for encoding errors (default is "strict"). - _embedding (list[float]): The embedding of the text artifact (default is an empty list). - - Properties: - embedding (Optional[list[float]]): The embedding of the text artifact. - - Methods: - __add__(self, other: BaseArtifact) -> TextArtifact: Concatenates the text value of the artifact with another artifact. - __bool__(self) -> bool: Checks if the text value of the artifact is non-empty. - generate_embedding(self, driver: BaseEmbeddingModel) -> Optional[list[float]]: Generates the embedding of the text artifact using a given embedding model. - token_count(self, tokenizer: BaseTokenizer) -> int: Counts the number of tokens in the text artifact using a given tokenizer. - to_bytes(self) -> bytes: Converts the text value of the artifact to bytes using the specified encoding and error handler. - """ - - value: str - encoding: str = "utf-8" - encoding_error_handler: str = "strict" - tokenizer: Callable = None - _embedding: list[float] = field(default_factory=list) - - @property - def embedding(self) -> list[float] | None: - return None if len(self._embedding) == 0 else self._embedding - - def __add__(self, other: BaseArtifact) -> TextArtifact: - return TextArtifact(self.value + other.value) - - def __bool__(self) -> bool: - return bool(self.value.strip()) - - def generate_embedding(self, model) -> list[float] | None: - self._embedding.clear() - self._embedding.extend(model.embed_string(str(self.value))) - - return self.embedding - - def token_count(self) -> int: - return self.tokenizer.count_tokens(str(self.value)) - - def to_bytes(self) -> bytes: - return self.value.encode( - encoding=self.encoding, errors=self.encoding_error_handler - )