diff options
Diffstat (limited to 'autogpts/autogpt/autogpt/file_workspace/__init__.py')
-rw-r--r-- | autogpts/autogpt/autogpt/file_workspace/__init__.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/autogpts/autogpt/autogpt/file_workspace/__init__.py b/autogpts/autogpt/autogpt/file_workspace/__init__.py new file mode 100644 index 000000000..a0e06e38f --- /dev/null +++ b/autogpts/autogpt/autogpt/file_workspace/__init__.py @@ -0,0 +1,46 @@ +import enum +from pathlib import Path +from typing import Optional + +from .base import FileWorkspace + + +class FileWorkspaceBackendName(str, enum.Enum): + LOCAL = "local" + GCS = "gcs" + S3 = "s3" + + +def get_workspace( + backend: FileWorkspaceBackendName, *, id: str = "", root_path: Optional[Path] = None +) -> FileWorkspace: + assert bool(root_path) != bool(id), "Specify root_path or id to get workspace" + if root_path is None: + root_path = Path(f"/workspaces/{id}") + + match backend: + case FileWorkspaceBackendName.LOCAL: + from .local import FileWorkspaceConfiguration, LocalFileWorkspace + + config = FileWorkspaceConfiguration.from_env() + config.root = root_path + return LocalFileWorkspace(config) + case FileWorkspaceBackendName.S3: + from .s3 import S3FileWorkspace, S3FileWorkspaceConfiguration + + config = S3FileWorkspaceConfiguration.from_env() + config.root = root_path + return S3FileWorkspace(config) + case FileWorkspaceBackendName.GCS: + from .gcs import GCSFileWorkspace, GCSFileWorkspaceConfiguration + + config = GCSFileWorkspaceConfiguration.from_env() + config.root = root_path + return GCSFileWorkspace(config) + + +__all__ = [ + "FileWorkspace", + "FileWorkspaceBackendName", + "get_workspace", +] |