Skip to content

LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows

1.4 KB
Raw Blame
"""File storage utilities for the legacy executor.

Adapted from ``prompt-service/.../utils/file_utils.py``.
Returns the appropriate ``FileStorage`` instance based on execution source.
"""

from executor.executors.constants import ExecutionSource, FileStorageKeys

from unstract.sdk1.file_storage import FileStorage
from unstract.sdk1.file_storage.constants import StorageType
from unstract.sdk1.file_storage.env_helper import EnvHelper


class FileUtils:
    @staticmethod
    def get_fs_instance(execution_source: str) -> FileStorage:
        """Returns a FileStorage instance based on the execution source.

        Args:
            execution_source: The source from which the execution is triggered.

        Returns:
            FileStorage: The file storage instance — Permanent/Shared temporary.

        Raises:
            ValueError: If the execution source is invalid.
        """
        if execution_source == ExecutionSource.IDE.value:
            return EnvHelper.get_storage(
                storage_type=StorageType.PERMANENT,
                env_name=FileStorageKeys.PERMANENT_REMOTE_STORAGE,
            )

        if execution_source == ExecutionSource.TOOL.value:
            return EnvHelper.get_storage(
                storage_type=StorageType.SHARED_TEMPORARY,
                env_name=FileStorageKeys.TEMPORARY_REMOTE_STORAGE,
            )

        raise ValueError(f"Invalid execution source: {execution_source}")