-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use generics for loaders, remove instances of path
- Loading branch information
1 parent
62b6e17
commit 6b3bc8b
Showing
34 changed files
with
79 additions
and
137 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
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
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
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,10 +1,8 @@ | ||
from pathlib import Path | ||
|
||
from griptape.loaders import ImageLoader | ||
from griptape.structures import Agent | ||
|
||
agent = Agent() | ||
|
||
image_artifact = ImageLoader().load(Path("tests/resources/mountain.jpg").read_bytes()) | ||
image_artifact = ImageLoader().load("tests/resources/mountain.jpg") | ||
|
||
agent.run([image_artifact, "What's in this image?"]) |
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,24 +1,29 @@ | ||
from __future__ import annotations | ||
|
||
from abc import ABC | ||
from typing import TYPE_CHECKING | ||
from os import PathLike | ||
from typing import TypeVar, Union | ||
|
||
from attrs import Factory, define, field | ||
|
||
from griptape.artifacts import BaseArtifact | ||
from griptape.drivers import BaseFileManagerDriver, LocalFileManagerDriver | ||
from griptape.loaders import BaseLoader | ||
|
||
if TYPE_CHECKING: | ||
from os import PathLike | ||
A = TypeVar("A", bound=BaseArtifact) | ||
|
||
|
||
@define | ||
class BaseFileLoader(BaseLoader, ABC): | ||
class BaseFileLoader(BaseLoader[Union[str, PathLike], bytes, A], ABC): | ||
file_manager_driver: BaseFileManagerDriver = field( | ||
default=Factory(lambda: LocalFileManagerDriver(workdir=None)), | ||
kw_only=True, | ||
) | ||
encoding: str = field(default="utf-8", kw_only=True) | ||
|
||
def fetch(self, source: str | PathLike, *args, **kwargs) -> str | bytes: | ||
return self.file_manager_driver.load_file(str(source), *args, **kwargs).value | ||
def fetch(self, source: str | PathLike) -> bytes: | ||
data = self.file_manager_driver.load_file(str(source)).value | ||
if isinstance(data, str): | ||
return data.encode(self.encoding) | ||
else: | ||
return data |
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
Oops, something went wrong.