Skip to content

Commit

Permalink
Merge branch 'main' into fix/avoid-conditionally-hiding-the-mark-hori…
Browse files Browse the repository at this point in the history
…zontal-lines-field
  • Loading branch information
athul-rs authored Jan 31, 2025
2 parents ab26646 + 10f48e0 commit 57d8d86
Show file tree
Hide file tree
Showing 47 changed files with 1,097 additions and 572 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ repos:
--settings-path=pyproject.toml,
]
- repo: https://github.com/hadialqattan/pycln
rev: v2.4.0
rev: v2.5.0
hooks:
- id: pycln
args: [--config=pyproject.toml]
Expand Down
6 changes: 2 additions & 4 deletions backend/api_v2/api_deployment_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from api_v2.constants import ApiExecution
from api_v2.deployment_helper import DeploymentHelper
from api_v2.exceptions import InvalidAPIRequest, NoActiveAPIKeyError
from api_v2.exceptions import NoActiveAPIKeyError
from api_v2.models import APIDeployment
from api_v2.postman_collection.dto import PostmanCollection
from api_v2.serializers import (
Expand Down Expand Up @@ -47,16 +47,14 @@ def initialize_request(
def post(
self, request: Request, org_name: str, api_name: str, api: APIDeployment
) -> Response:
file_objs = request.FILES.getlist(ApiExecution.FILES_FORM_DATA)
serializer = ExecutionRequestSerializer(data=request.data)
serializer.is_valid(raise_exception=True)
file_objs = serializer.validated_data.get(ApiExecution.FILES_FORM_DATA)
timeout = serializer.validated_data.get(ApiExecution.TIMEOUT_FORM_DATA)
include_metadata = serializer.validated_data.get(ApiExecution.INCLUDE_METADATA)
include_metrics = serializer.validated_data.get(ApiExecution.INCLUDE_METRICS)
use_file_history = serializer.validated_data.get(ApiExecution.USE_FILE_HISTORY)
tag_names = serializer.validated_data.get(ApiExecution.TAGS)
if not file_objs or len(file_objs) == 0:
raise InvalidAPIRequest("File shouldn't be empty")
response = DeploymentHelper.execute_workflow(
organization_name=org_name,
api=api,
Expand Down
3 changes: 2 additions & 1 deletion backend/api_v2/key_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from api_v2.exceptions import UnauthorizedKey
from api_v2.models import APIDeployment, APIKey
from api_v2.serializers import APIKeySerializer
from django.core.exceptions import ValidationError
from pipeline_v2.models import Pipeline
from rest_framework.request import Request
from workflow_manager.workflow_v2.workflow_helper import WorkflowHelper
Expand All @@ -29,7 +30,7 @@ def validate_api_key(
api_key_instance: APIKey = APIKey.objects.get(api_key=api_key)
if not KeyHelper.has_access(api_key_instance, instance):
raise UnauthorizedKey()
except APIKey.DoesNotExist:
except (APIKey.DoesNotExist, ValidationError):
raise UnauthorizedKey()

@staticmethod
Expand Down
21 changes: 21 additions & 0 deletions backend/api_v2/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
from rest_framework.serializers import (
BooleanField,
CharField,
FileField,
IntegerField,
JSONField,
ListField,
ModelSerializer,
Serializer,
ValidationError,
Expand Down Expand Up @@ -115,12 +117,31 @@ class ExecutionRequestSerializer(TagParamsSerializer):
e.g:'tag1,tag2-name,tag3_name'
"""

MAX_FILES_ALLOWED = 32

timeout = IntegerField(
min_value=-1, max_value=ApiExecution.MAXIMUM_TIMEOUT_IN_SEC, default=-1
)
include_metadata = BooleanField(default=False)
include_metrics = BooleanField(default=False)
use_file_history = BooleanField(default=False)
files = ListField(
child=FileField(),
required=True,
allow_empty=False,
error_messages={
"required": "At least one file must be provided.",
"empty": "The file list cannot be empty.",
},
)

def validate_files(self, value):
"""Validate the files field."""
if len(value) == 0:
raise ValidationError("The file list cannot be empty.")
if len(value) > self.MAX_FILES_ALLOWED:
raise ValidationError(f"Maximum '{self.MAX_FILES_ALLOWED}' files allowed.")
return value


class ExecutionQuerySerializer(Serializer):
Expand Down
3 changes: 0 additions & 3 deletions backend/backend/public_urls_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
from django.conf.urls.static import static
from django.urls import include, path

path_prefix = settings.PATH_PREFIX
api_path_prefix = settings.API_DEPLOYMENT_PATH_PREFIX

urlpatterns = [
path("", include("account_v2.urls")),
# Connector OAuth
Expand Down
7 changes: 6 additions & 1 deletion backend/backend/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ def get_required_setting(
"middleware.cache_control.CacheControlMiddleware",
]

TENANT_SUBFOLDER_PREFIX = f"/{PATH_PREFIX}/unstract"
TENANT_SUBFOLDER_PREFIX = f"{PATH_PREFIX}/unstract"
SHOW_PUBLIC_IF_NO_TENANT_FOUND = True

TEMPLATES = [
Expand Down Expand Up @@ -435,6 +435,11 @@ def get_required_setting(
"django_filters.rest_framework.DjangoFilterBackend",
"rest_framework.filters.OrderingFilter",
],
# For API versioning
"DEFAULT_VERSIONING_CLASS": "rest_framework.versioning.URLPathVersioning",
"DEFAULT_VERSION": "v1",
"ALLOWED_VERSIONS": ["v1"],
"VERSION_PARAM": "version",
}

# These paths will work without authentication
Expand Down
6 changes: 0 additions & 6 deletions backend/file_management/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,3 @@ class FileInformationKey:
FILE_UPLOAD_MAX_SIZE = 100 * 1024 * 1024
FILE_UPLOAD_ALLOWED_EXT = ["pdf"]
FILE_UPLOAD_ALLOWED_MIME = ["application/pdf"]


class FileViewTypes:
ORIGINAL = "ORIGINAL"
EXTRACT = "EXTRACT"
SUMMARIZE = "SUMMARIZE"
7 changes: 3 additions & 4 deletions backend/middleware/organization_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

class OrganizationMiddleware(MiddlewareMixin):
def process_request(self, request):
tenant_prefix = settings.TENANT_SUBFOLDER_PREFIX.rstrip("/") + "/"
pattern = rf"^{tenant_prefix}(?P<org_id>[^/]+)/"
pattern = r"^/api/(?P<version>v[12])/unstract/(?P<org_id>[^/]+)/"

# Check if the URL matches the pattern with organization ID
match = re.match(pattern, request.path)
Expand All @@ -17,12 +16,12 @@ def process_request(self, request):
re.match(path, request.path)
for path in settings.ORGANIZATION_MIDDLEWARE_WHITELISTED_PATHS
):
request.path_info = "/" + request.path_info
return

org_id = match.group("org_id")
version = match.group("version")
request.organization_id = org_id
new_path = re.sub(pattern, "/" + tenant_prefix, request.path_info)
new_path = re.sub(pattern, f"/api/{version}/unstract/", request.path_info)
request.path_info = new_path
else:
request.organization_id = None
68 changes: 34 additions & 34 deletions backend/pdm.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,7 @@ def _fetch_response(
TSPKeys.FILE_HASH: file_hash,
TSPKeys.FILE_PATH: doc_path,
Common.LOG_EVENTS_ID: StateStore.get(Common.LOG_EVENTS_ID),
TSPKeys.EXECUTION_SOURCE: ExecutionSource.IDE.value,
}

util = PromptIdeBaseTool(log_level=LogLevel.INFO, org_id=org_id)
Expand Down
2 changes: 1 addition & 1 deletion backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies = [
"python-socketio==5.9.0", # For log_events
"social-auth-app-django==5.3.0", # For OAuth
"social-auth-core==4.4.2", # For OAuth
"unstract-sdk~=0.55.0rc2",
"unstract-sdk~=0.56.0rc4",
# ! IMPORTANT!
# Indirect local dependencies usually need to be added in their own projects
# as: https://pdm-project.org/latest/usage/dependency/#local-dependencies.
Expand Down
4 changes: 2 additions & 2 deletions backend/sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ REMOTE_PROMPT_STUDIO_FILE_PATH=

# Structure Tool Image (Runs prompt studio exported tools)
# https://hub.docker.com/r/unstract/tool-structure
STRUCTURE_TOOL_IMAGE_URL="docker:unstract/tool-structure:0.0.56"
STRUCTURE_TOOL_IMAGE_URL="docker:unstract/tool-structure:0.0.60"
STRUCTURE_TOOL_IMAGE_NAME="unstract/tool-structure"
STRUCTURE_TOOL_IMAGE_TAG="0.0.56"
STRUCTURE_TOOL_IMAGE_TAG="0.0.60"

# Feature Flags
EVALUATION_SERVER_IP=unstract-flipt
Expand Down
Loading

0 comments on commit 57d8d86

Please sign in to comment.