From 3be930424e841378c54ceeffb5e3206eff78287e Mon Sep 17 00:00:00 2001 From: jagadeeswaran-zipstack Date: Fri, 3 Jan 2025 02:25:18 +0530 Subject: [PATCH 1/2] added fix to filter noOp adapters for common users --- backend/adapter_processor_v2/adapter_processor.py | 12 ++++++++++-- backend/adapter_processor_v2/views.py | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/backend/adapter_processor_v2/adapter_processor.py b/backend/adapter_processor_v2/adapter_processor.py index 062d26700..47fc6d90d 100644 --- a/backend/adapter_processor_v2/adapter_processor.py +++ b/backend/adapter_processor_v2/adapter_processor.py @@ -44,17 +44,25 @@ def get_json_schema(adapter_id: str) -> dict[str, Any]: return schema_details @staticmethod - def get_all_supported_adapters(type: str) -> list[dict[Any, Any]]: + def get_all_supported_adapters(user_email: str, type: str) -> list[dict[Any, Any]]: """Function to return list of all supported adapters.""" supported_adapters = [] updated_adapters = [] updated_adapters = AdapterProcessor.__fetch_adapters_by_key_value( AdapterKeys.ADAPTER_TYPE, type ) + is_zipstack_or_unstract_user = ( + "@zipstack.com" in user_email or "@unstract.com" in user_email + ) + for each_adapter in updated_adapters: + adapter_id = each_adapter.get(AdapterKeys.ID) + if not is_zipstack_or_unstract_user and adapter_id.startswith("noOp"): + continue + supported_adapters.append( { - AdapterKeys.ID: each_adapter.get(AdapterKeys.ID), + AdapterKeys.ID: adapter_id, AdapterKeys.NAME: each_adapter.get(AdapterKeys.NAME), AdapterKeys.DESCRIPTION: each_adapter.get(AdapterKeys.DESCRIPTION), AdapterKeys.ICON: each_adapter.get(AdapterKeys.ICON), diff --git a/backend/adapter_processor_v2/views.py b/backend/adapter_processor_v2/views.py index 92eb5f2e7..299716d87 100644 --- a/backend/adapter_processor_v2/views.py +++ b/backend/adapter_processor_v2/views.py @@ -95,7 +95,7 @@ def list( or adapter_type == AdapterKeys.OCR ): json_schema = AdapterProcessor.get_all_supported_adapters( - type=adapter_type + type=adapter_type, user_email=request.user.email ) return Response(json_schema, status=status.HTTP_200_OK) else: From f095bf86b0276a000e0dc2131521a5ddb110c6f3 Mon Sep 17 00:00:00 2001 From: jagadeeswaran-zipstack Date: Fri, 3 Jan 2025 10:45:29 +0530 Subject: [PATCH 2/2] added enum for allowed domains --- backend/adapter_processor_v2/adapter_processor.py | 8 ++++---- backend/adapter_processor_v2/constants.py | 12 ++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/backend/adapter_processor_v2/adapter_processor.py b/backend/adapter_processor_v2/adapter_processor.py index 47fc6d90d..33fccec88 100644 --- a/backend/adapter_processor_v2/adapter_processor.py +++ b/backend/adapter_processor_v2/adapter_processor.py @@ -3,7 +3,7 @@ from typing import Any, Optional from account_v2.models import User -from adapter_processor_v2.constants import AdapterKeys +from adapter_processor_v2.constants import AdapterKeys, AllowedDomains from adapter_processor_v2.exceptions import ( InternalServiceError, InValidAdapterId, @@ -51,13 +51,13 @@ def get_all_supported_adapters(user_email: str, type: str) -> list[dict[Any, Any updated_adapters = AdapterProcessor.__fetch_adapters_by_key_value( AdapterKeys.ADAPTER_TYPE, type ) - is_zipstack_or_unstract_user = ( - "@zipstack.com" in user_email or "@unstract.com" in user_email + is_special_user = any( + identifier in user_email for identifier in AllowedDomains.list() ) for each_adapter in updated_adapters: adapter_id = each_adapter.get(AdapterKeys.ID) - if not is_zipstack_or_unstract_user and adapter_id.startswith("noOp"): + if not is_special_user and adapter_id.startswith("noOp"): continue supported_adapters.append( diff --git a/backend/adapter_processor_v2/constants.py b/backend/adapter_processor_v2/constants.py index 6557491b9..3b849a72b 100644 --- a/backend/adapter_processor_v2/constants.py +++ b/backend/adapter_processor_v2/constants.py @@ -1,3 +1,6 @@ +from enum import Enum + + class AdapterKeys: JSON_SCHEMA = "json_schema" ADAPTER_TYPE = "adapter_type" @@ -27,3 +30,12 @@ class AdapterKeys: ADAPTER_NAME = "adapter_name" ADAPTER_CREATED_BY = "created_by_email" ADAPTER_CONTEXT_WINDOW_SIZE = "context_window_size" + + +class AllowedDomains(Enum): + ZIPSTACK = "@zipstack.com" + UNSTRACT = "@unstract.com" + + @staticmethod + def list(): + return list(map(lambda c: c.value, AllowedDomains))