Skip to content

Commit

Permalink
Merge branch 'fix/app-deployment-plugin' of https://github.com/Zipsta…
Browse files Browse the repository at this point in the history
…ck/unstract into feat/app-deployment-with-multidoc-chat
  • Loading branch information
johnyrahul committed Jun 12, 2024
2 parents 55e6cee + 258ec13 commit fad0025
Show file tree
Hide file tree
Showing 78 changed files with 5,127 additions and 856 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/production-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
- name: Build and push images
working-directory: ./docker
run: |
DOCKER_VERSION_TAG = ${{ github.event.release.tag_name || github.event.inputs.tag}}
DOCKER_VERSION_TAG=${{ github.event.release.tag_name || github.event.inputs.tag}}
VERSION=$DOCKER_VERSION_TAG docker-compose -f docker-compose.build.yaml build --no-cache ${{ matrix.service_name }}
docker push unstract/${{ matrix.service_name }}:$DOCKER_VERSION_TAG
if [ "${{ github.event_name }}" = "release" ]; then
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ celerybeat.pid
*.sage.py

# Environments
test*.env
.env
.env.export
.venv*
Expand Down
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ repos:
# - id: actionlint-docker
# args: [-ignore, 'label ".+" is unknown']
- repo: https://github.com/psf/black
rev: 24.4.0
rev: 24.4.2
hooks:
- id: black
args: [--config=pyproject.toml, -l 88]
Expand Down Expand Up @@ -89,14 +89,14 @@ repos:
hooks:
- id: docformatter
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.2
rev: v3.16.0
hooks:
- id: pyupgrade
entry: pyupgrade --py39-plus --keep-runtime-typing
types:
- python
- repo: https://github.com/gitleaks/gitleaks
rev: v8.18.2
rev: v8.18.3
hooks:
- id: gitleaks
# - repo: https://github.com/hadolint/hadolint
Expand Down Expand Up @@ -133,14 +133,14 @@ repos:
hooks:
- id: htmlhint
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.39.0
rev: v0.41.0
hooks:
- id: markdownlint
args: [--disable, MD013]
- id: markdownlint-fix
args: [--disable, MD013]
- repo: https://github.com/pdm-project/pdm
rev: 2.15.0
rev: 2.15.4
hooks:
- id: pdm-lock-check
# - repo: local
Expand Down
19 changes: 15 additions & 4 deletions backend/feature_flag/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,20 @@
This module defines the URL patterns for the feature_flags app.
"""

import feature_flag.views as views
from django.urls import path
from feature_flag.views import FeatureFlagViewSet
from rest_framework.urlpatterns import format_suffix_patterns

urlpatterns = [
path("evaluate/", views.evaluate_feature_flag, name="evaluate_feature_flag"),
]
feature_flags_list = FeatureFlagViewSet.as_view(
{
"post": "evaluate",
"get": "list",
}
)

urlpatterns = format_suffix_patterns(
[
path("evaluate/", feature_flags_list, name="evaluate_feature_flag"),
path("flags/", feature_flags_list, name="list_feature_flags"),
]
)
56 changes: 29 additions & 27 deletions backend/feature_flag/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,43 @@

import logging

from rest_framework import status
from rest_framework.decorators import api_view
from rest_framework.request import Request
from rest_framework import status, viewsets
from rest_framework.response import Response
from utils.request.feature_flag import check_feature_flag_status
from utils.request.feature_flag import check_feature_flag_status, list_all_flags

logger = logging.getLogger(__name__)


@api_view(["POST"])
def evaluate_feature_flag(request: Request) -> Response:
"""Function to evaluate the feature flag.
class FeatureFlagViewSet(viewsets.ViewSet):
"""A simple ViewSet for evaluating feature flag."""

To-Do: Refactor to a class based view, use serializers (DRF).
def evaluate(self, request):
try:
flag_key = request.data.get("flag_key")

Args:
request: request object
if not flag_key:
return Response(
{"message": "Request parameters are missing."},
status=status.HTTP_400_BAD_REQUEST,
)

Returns:
evaluate response
"""
try:
flag_key = request.data.get("flag_key")

if not flag_key:
flag_enabled = check_feature_flag_status(flag_key)
return Response({"flag_status": flag_enabled}, status=status.HTTP_200_OK)
except Exception as e:
logger.error("No response from server: %s", e)
return Response(
{"message": "Request paramteres are missing."},
status=status.HTTP_400_BAD_REQUEST,
{"message": "No response from server"},
status=status.HTTP_500_INTERNAL_SERVER_ERROR,
)

flag_enabled = check_feature_flag_status(flag_key)
return Response({"flag_status": flag_enabled}, status=status.HTTP_200_OK)
except Exception as e:
logger.error("No response from server: %s", e)
return Response(
{"message": "No response from server"},
status=status.HTTP_500_INTERNAL_SERVER_ERROR,
)
def list(self, request):
try:
namespace_key = request.query_params.get("namespace", "default")
feature_flags = list_all_flags(namespace_key)
return Response({"feature_flags": feature_flags}, status=status.HTTP_200_OK)
except Exception as e:
logger.error("No response from server: %s", e)
return Response(
{"message": "No response from server"},
status=status.HTTP_500_INTERNAL_SERVER_ERROR,
)
54 changes: 38 additions & 16 deletions backend/file_management/file_management_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,28 +181,50 @@ def fetch_file_contents(file_system: UnstractFileSystem, file_path: str) -> Any:
else:
raise InvalidFileType

@staticmethod
def _delete_file(fs, file_path):
try:
fs.rm(file_path)
except FileNotFoundError:
FileManagerHelper.logger.info(f"File not found: {file_path}")
except Exception as e:
FileManagerHelper.logger.info(f"Unable to delete file {e}")
raise FileDeletionFailed(f"Unable to delete file {e}")

@staticmethod
def _get_base_path(file_system: UnstractFileSystem, path: str):
fs = file_system.get_fsspec_fs()
base_path = getattr(
file_system if hasattr(file_system, "path") else fs, "path", path
)
base_path = base_path.rstrip("/") + "/"
return base_path

@staticmethod
def delete_file(file_system: UnstractFileSystem, path: str, file_name: str) -> bool:
fs = file_system.get_fsspec_fs()
base_path = FileManagerHelper._get_base_path(file_system, path)
file_path = str(Path(base_path) / file_name)
FileManagerHelper._delete_file(fs, file_path)
return True

file_path = f"{path}"
try:
if file_system.path and (not path or path == "/"):
file_path = f"{file_system.path}/"
except AttributeError:
if fs.path and (not path or path == "/"):
file_path = f"{fs.path}/"
@staticmethod
def delete_related_files(
file_system: UnstractFileSystem,
path: str,
file_name: str,
directories: list[str],
) -> bool:
fs = file_system.get_fsspec_fs()
base_path = FileManagerHelper._get_base_path(file_system, path)

file_path = file_path + "/" if not file_path.endswith("/") else file_path
base_file_name, _ = os.path.splitext(file_name)
file_name_txt = base_file_name + ".txt"

# adding filename with path
file_path += file_name
try:
with fs.open(file_path, mode="wb") as remote_file:
return remote_file.fs.delete(remote_file.path) # type:ignore
except Exception as e:
FileManagerHelper.logger.info(f"Unable to delete file {e}")
raise FileDeletionFailed(f"Unable to delete file {e}")
for directory in directories:
file_path = str(Path(base_path) / directory / file_name_txt)
FileManagerHelper._delete_file(fs, file_path)
return True

@staticmethod
def handle_sub_directory_for_tenants(
Expand Down
18 changes: 16 additions & 2 deletions backend/pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions backend/prompt_studio/prompt_studio/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ class ToolStudioPromptKeys:
PROMPT_KEY = "prompt_key"
EVAL_METRIC_PREFIX = "eval_"
EVAL_RESULT_DELIM = "__"
SEQUENCE_NUMBER = "sequence_number"
START_SEQUENCE_NUMBER = "start_sequence_number"
END_SEQUENCE_NUMBER = "end_sequence_number"
PROMPT_ID = "prompt_id"


class ToolStudioPromptErrors:
Expand Down
58 changes: 58 additions & 0 deletions backend/prompt_studio/prompt_studio/controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import logging

from prompt_studio.prompt_studio.constants import ToolStudioPromptKeys
from prompt_studio.prompt_studio.helper import PromptStudioHelper
from prompt_studio.prompt_studio.models import ToolStudioPrompt
from prompt_studio.prompt_studio.serializers import ReorderPromptsSerializer
from rest_framework import status
from rest_framework.request import Request
from rest_framework.response import Response

logger = logging.getLogger(__name__)


class PromptStudioController:
def reorder_prompts(self, request: Request) -> Response:
"""Reorder the sequence of prompts based on the start and end sequence
numbers.
This action handles the reordering of prompts by updating their sequence
numbers. It increments or decrements the sequence numbers of the relevant
prompts to reflect the new order. If the start and end sequence numbers
are equal, it returns a bad request response.
Args:
request (Request): The HTTP request object containing the data to
reorder prompts.
Returns:
Response: A Response object with the status of the reordering operation.
"""
try:
# Validate request data
serializer = ReorderPromptsSerializer(data=request.data)
serializer.is_valid(raise_exception=True)

# Extract validated data from the serializer
start_sequence_number = serializer.validated_data.get(
ToolStudioPromptKeys.START_SEQUENCE_NUMBER
)
end_sequence_number = serializer.validated_data.get(
ToolStudioPromptKeys.END_SEQUENCE_NUMBER
)
prompt_id = serializer.validated_data.get(ToolStudioPromptKeys.PROMPT_ID)

filtered_prompts_data = PromptStudioHelper.reorder_prompts_helper(
prompt_id=prompt_id,
start_sequence_number=start_sequence_number,
end_sequence_number=end_sequence_number,
)

logger.info("Re-ordering completed successfully.")
return Response(status=status.HTTP_200_OK, data=filtered_prompts_data)

except ToolStudioPrompt.DoesNotExist:
logger.error(f"Prompt with ID {prompt_id} not found.")
return Response(
status=status.HTTP_404_NOT_FOUND, data={"detail": "Prompt not found."}
)
Loading

0 comments on commit fad0025

Please sign in to comment.