Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Show No Op adapters in UI only for zipstack and unstract domain emails #1046

Merged
merged 3 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions backend/adapter_processor_v2/adapter_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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_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_special_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),
Expand Down
12 changes: 12 additions & 0 deletions backend/adapter_processor_v2/constants.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from enum import Enum


class AdapterKeys:
JSON_SCHEMA = "json_schema"
ADAPTER_TYPE = "adapter_type"
Expand Down Expand Up @@ -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))
2 changes: 1 addition & 1 deletion backend/adapter_processor_v2/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def list(
or adapter_type == AdapterKeys.OCR
):
json_schema = AdapterProcessor.get_all_supported_adapters(
jagadeeswaran-zipstack marked this conversation as resolved.
Show resolved Hide resolved
type=adapter_type
type=adapter_type, user_email=request.user.email
)
return Response(json_schema, status=status.HTTP_200_OK)
else:
Expand Down
Loading