diff options
Diffstat (limited to 'autogpts/autogpt/autogpt/file_workspace/__init__.py')
-rw-r--r-- | autogpts/autogpt/autogpt/file_workspace/__init__.py | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/autogpts/autogpt/autogpt/file_workspace/__init__.py b/autogpts/autogpt/autogpt/file_workspace/__init__.py index 76a26eefe..a0e06e38f 100644 --- a/autogpts/autogpt/autogpt/file_workspace/__init__.py +++ b/autogpts/autogpt/autogpt/file_workspace/__init__.py @@ -1,5 +1,46 @@ -from .file_workspace import FileWorkspace +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", ] |