Skip to content

Commit

Permalink
[FIX] Env standardization for Backend. (#1050)
Browse files Browse the repository at this point in the history
* env standadization for backend

* Sample envs for remote storage

* Sample envs for remote storage

---------

Signed-off-by: Gayathri <[email protected]>
Co-authored-by: Gayathri <[email protected]>
Co-authored-by: gayathrivijayakumar <[email protected]>
  • Loading branch information
3 people authored Jan 9, 2025
1 parent 8da57d3 commit b1bef07
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 77 deletions.
10 changes: 6 additions & 4 deletions backend/prompt_studio/prompt_studio_core_v2/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
from django.db.models import QuerySet
from file_management.file_management_helper import FileManagerHelper
from prompt_studio.prompt_studio_core_v2.constants import DefaultPrompts
from utils.file_storage.constants import FileStorageType
from utils.file_storage.helpers.common_file_helper import FileStorageHelper
from unstract.sdk.file_storage.constants import StorageType
from unstract.sdk.file_storage.env_helper import EnvHelper
from utils.file_storage.constants import FileStorageKeys
from utils.file_storage.helpers.prompt_studio_file_helper import PromptStudioFileHelper
from utils.models.base_model import BaseModel
from utils.models.organization_mixin import (
Expand Down Expand Up @@ -155,8 +156,9 @@ def delete(self, organization_id=None, *args, **kwargs):
logger.error(f"Error: {file_path} : {e.strerror}")
# Continue with the deletion of the tool
else:
fs_instance = FileStorageHelper.initialize_file_storage(
type=FileStorageType.PERMANENT
fs_instance = EnvHelper.get_storage(
storage_type=StorageType.PERMANENT,
env_name=FileStorageKeys.PERMANENT_REMOTE_STORAGE,
)
file_path = PromptStudioFileHelper.get_or_create_prompt_studio_subdirectory(
organization_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@
from unstract.sdk.constants import LogLevel
from unstract.sdk.exceptions import IndexingError, SdkError
from unstract.sdk.file_storage import FileStorage, FileStorageProvider
from unstract.sdk.file_storage.constants import StorageType
from unstract.sdk.file_storage.env_helper import EnvHelper
from unstract.sdk.index import Index
from unstract.sdk.prompt import PromptTool
from unstract.sdk.utils.tool_utils import ToolUtils
from utils.file_storage.constants import FileStorageType
from utils.file_storage.helpers.common_file_helper import FileStorageHelper
from utils.file_storage.constants import FileStorageKeys
from utils.file_storage.helpers.prompt_studio_file_helper import PromptStudioFileHelper
from utils.local_context import StateStore

Expand Down Expand Up @@ -395,8 +396,9 @@ def index_document(
process_text=process_text,
)
else:
fs_instance = FileStorageHelper.initialize_file_storage(
type=FileStorageType.PERMANENT
fs_instance = EnvHelper.get_storage(
storage_type=StorageType.PERMANENT,
env_name=FileStorageKeys.PERMANENT_REMOTE_STORAGE,
)
doc_id = PromptStudioHelper.dynamic_indexer(
profile_manager=default_profile,
Expand Down Expand Up @@ -800,8 +802,9 @@ def _fetch_response(
process_text=process_text,
)
else:
fs_instance = FileStorageHelper.initialize_file_storage(
type=FileStorageType.PERMANENT
fs_instance = EnvHelper.get_storage(
storage_type=StorageType.PERMANENT,
env_name=FileStorageKeys.PERMANENT_REMOTE_STORAGE,
)
index_result = PromptStudioHelper.dynamic_indexer(
profile_manager=profile_manager,
Expand Down Expand Up @@ -1154,8 +1157,9 @@ def _fetch_single_pass_response(
process_text=process_text,
)
else:
fs_instance = FileStorageHelper.initialize_file_storage(
type=FileStorageType.PERMANENT
fs_instance = EnvHelper.get_storage(
storage_type=StorageType.PERMANENT,
env_name=FileStorageKeys.PERMANENT_REMOTE_STORAGE,
)
index_result = PromptStudioHelper.dynamic_indexer(
profile_manager=default_profile,
Expand Down
8 changes: 4 additions & 4 deletions backend/sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,6 @@ TOOL_REGISTRY_CONFIG_PATH="/data/tool_registry_config"
# Flipt Service
FLIPT_SERVICE_AVAILABLE=False

# Remote storage config for tool registry
TOOL_REGISTRY_STORAGE_CREDENTIALS='{"provider":"local"}'


# File System Configuration for Workflow and API Execution

# Directory Prefixes for storing execution files
Expand All @@ -165,5 +161,9 @@ WORKFLOW_EXECUTION_FILE_STORAGE_CREDENTIALS='{"provider":"minio","credentials":
# Storage Provider for API Execution
API_FILE_STORAGE_CREDENTIALS='{"provider": "minio", "credentials": {"endpoint_url": "http://unstract-minio:9000", "key": "XXX", "secret": "XXX"}}'

#Remote storage related envs
PERMANENT_REMOTE_STORAGE={"provider":"gcs","credentials":<credentials>}
REMOTE_PROMPT_STUDIO_FILE_PATH="<bucket_name>/prompt_studio_data/"

# Storage Provider for Tool registry
TOOL_REGISTRY_STORAGE_CREDENTIALS='{"provider":"local"}'
4 changes: 2 additions & 2 deletions backend/utils/file_storage/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@


class FileStorageKeys:
FILE_STORAGE_PROVIDER = "FILE_STORAGE_PROVIDER"
FILE_STORAGE_CREDENTIALS = "FILE_STORAGE_CREDENTIALS"
PERMANENT_REMOTE_STORAGE = "PERMANENT_REMOTE_STORAGE"
TEMPORARY_REMOTE_STORAGE = "TEMPORARY_REMOTE_STORAGE"


class FileStorageType(Enum):
Expand Down
47 changes: 0 additions & 47 deletions backend/utils/file_storage/helpers/common_file_helper.py

This file was deleted.

25 changes: 15 additions & 10 deletions backend/utils/file_storage/helpers/prompt_studio_file_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

from file_management.file_management_helper import FileManagerHelper
from unstract.sdk.file_storage import FileStorage
from utils.file_storage.constants import FileStorageConstants, FileStorageType
from utils.file_storage.helpers.common_file_helper import FileStorageHelper
from unstract.sdk.file_storage.constants import StorageType
from unstract.sdk.file_storage.env_helper import EnvHelper
from utils.file_storage.constants import FileStorageConstants, FileStorageKeys

from unstract.core.utilities import UnstractUtils

Expand Down Expand Up @@ -37,8 +38,9 @@ def get_or_create_prompt_studio_subdirectory(
extract_file_path = str(Path(file_path) / "extract")
summarize_file_path = str(Path(file_path) / "summarize")
if is_create:
fs_instance = FileStorageHelper.initialize_file_storage(
type=FileStorageType.PERMANENT
fs_instance = EnvHelper.get_storage(
storage_type=StorageType.PERMANENT,
env_name=FileStorageKeys.PERMANENT_REMOTE_STORAGE,
)
fs_instance.mkdir(file_path, create_parents=True)
fs_instance.mkdir(extract_file_path, create_parents=True)
Expand All @@ -57,8 +59,9 @@ def upload_for_ide(
tool_id (str): ID of the prompt studio tool
uploaded_file : File to upload to remote
"""
fs_instance = FileStorageHelper.initialize_file_storage(
type=FileStorageType.PERMANENT
fs_instance = EnvHelper.get_storage(
storage_type=StorageType.PERMANENT,
env_name=FileStorageKeys.PERMANENT_REMOTE_STORAGE,
)
file_system_path = (
PromptStudioFileHelper.get_or_create_prompt_studio_subdirectory(
Expand All @@ -77,8 +80,9 @@ def fetch_file_contents(
) -> Union[bytes, str]:
"""Method to fetch file contents from the remote location.
The path is constructed in runtime based on the args"""
fs_instance = FileStorageHelper.initialize_file_storage(
type=FileStorageType.PERMANENT
fs_instance = EnvHelper.get_storage(
storage_type=StorageType.PERMANENT,
env_name=FileStorageKeys.PERMANENT_REMOTE_STORAGE,
)
# Fetching legacy file path for lazy copy
# This has to be removed once the usage of FS APIs
Expand Down Expand Up @@ -139,8 +143,9 @@ def delete_for_ide(org_id: str, user_id: str, tool_id: str, file_name: str) -> b
"""Method to delete file in remote while the corresponsing prompt
studio project is deleted or the file is removed from the file manager.
This method handles deleted for related files as well."""
fs_instance = FileStorageHelper.initialize_file_storage(
type=FileStorageType.PERMANENT
fs_instance = EnvHelper.get_storage(
storage_type=StorageType.PERMANENT,
env_name=FileStorageKeys.PERMANENT_REMOTE_STORAGE,
)
file_system_path = (
PromptStudioFileHelper.get_or_create_prompt_studio_subdirectory(
Expand Down
5 changes: 5 additions & 0 deletions prompt-service/sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,8 @@ PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python

# Flipt Service
FLIPT_SERVICE_AVAILABLE=False


#Remote storage related envs
PERMANENT_REMOTE_STORAGE={"provider":"gcs","credentials":<credentials>}
REMOTE_PROMPT_STUDIO_FILE_PATH="<bucket_name>/prompt_studio_data/"
2 changes: 0 additions & 2 deletions prompt-service/src/unstract/prompt_service/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ class DBTableV2:


class FileStorageKeys:
FILE_STORAGE_PROVIDER = "FILE_STORAGE_PROVIDER"
FILE_STORAGE_CREDENTIALS = "FILE_STORAGE_CREDENTIALS"
PERMANENT_REMOTE_STORAGE = "PERMANENT_REMOTE_STORAGE"
TEMPORARY_REMOTE_STORAGE = "TEMPORARY_REMOTE_STORAGE"

Expand Down

0 comments on commit b1bef07

Please sign in to comment.