Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
0f9d76c
Implemented changes related to unstract subscription
tahierhussain Jan 8, 2025
78ddabf
Merge branch 'feat/unstract-payment-integration-fe' of github.com:Zip…
athul-rs Jan 8, 2025
f6e72a7
Have different home pages for OSS and Cloud
tahierhussain Jan 9, 2025
1fe2c52
Renamed the unstract subscription pages and replaced '<></>' with '<O…
tahierhussain Jan 9, 2025
8b5bd8e
Merge branch 'main' into feat/unstract-payment-integration-fe
tahierhussain Jan 9, 2025
988ba47
Updated import path of the TrialDaysInfo component
tahierhussain Jan 9, 2025
6481111
Merge branch 'feat/unstract-payment-integration-fe' of github.com:Zip…
tahierhussain Jan 9, 2025
b1348a9
Support 'readonly' parameter for all custom RJSF widgets
tahierhussain Jan 9, 2025
00b92a5
Transform the JSON schema for the LLM Whisperer V2 adapter for cloud
tahierhussain Jan 9, 2025
0b43097
Fixed Eslint issues
tahierhussain Jan 9, 2025
664d90c
Merge branch 'main' into feat/support-readonly-for-custom-rjsf-widget…
tahierhussain Jan 9, 2025
4d4c9dd
Code quality improvement
tahierhussain Jan 9, 2025
19225d1
Merge branch 'feat/support-readonly-for-custom-rjsf-widgets-and-trans…
tahierhussain Jan 9, 2025
f289d32
Allow JSON schema transform for LLMW V2 only for paid plan users
tahierhussain Jan 10, 2025
29785f6
Allow JSON schema transform for LLMW V2 only for paid plan users
tahierhussain Jan 10, 2025
895ff1b
Fix sonar issue
tahierhussain Jan 10, 2025
2fb9079
Merge branch 'main' into feat/support-readonly-for-custom-rjsf-widget…
tahierhussain Jan 10, 2025
aa228ec
Implemented the to structure the API path
tahierhussain Jan 13, 2025
563f303
Merge branch 'main' into feat/support-readonly-for-custom-rjsf-widget…
vishnuszipstack Jan 13, 2025
7ac75d6
Merge branch 'feat/unstract-payment-integration-fe' of github.com:Zip…
athul-rs Jan 15, 2025
ea1fdef
Merge branch 'feat/support-readonly-for-custom-rjsf-widgets-and-trans…
athul-rs Jan 15, 2025
a6eed67
Merge branch 'main' of github.com:Zipstack/unstract
athul-rs Jan 16, 2025
717e44b
Rearranged the onboard and subscription check APIs
tahierhussain Jan 17, 2025
ab1f8d8
Merge branch 'feat/unstract-payment-integration-fe' of github.com:Zip…
athul-rs Jan 17, 2025
9e7b9ef
Unstract payment supporting updates
athul-rs Jan 21, 2025
4e9722c
X2text metadata updates
athul-rs Jan 23, 2025
7f8caf0
Adapter update for unstarct payments
athul-rs Jan 23, 2025
fbefa61
Merge branch 'main' of github.com:Zipstack/unstract into feat/unstrac…
athul-rs Jan 23, 2025
ec57d6a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 23, 2025
cc962d0
Merge branch 'main' into feat/unstract-payments
athul-rs Jan 23, 2025
728e5eb
Minor fix in the API path
tahierhussain Jan 23, 2025
6a65040
Review comments updates
athul-rs Jan 23, 2025
2ebf29c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 23, 2025
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
27 changes: 27 additions & 0 deletions backend/adapter_processor_v2/adapter_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
InValidAdapterId,
TestAdapterError,
)
from cryptography.fernet import Fernet
from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist
from platform_settings_v2.platform_auth_service import PlatformAuthenticationService
Expand All @@ -23,6 +24,11 @@

logger = logging.getLogger(__name__)

try:
from plugins.subscription.time_trials.subscription_adapter import add_unstract_key
except ImportError:
add_unstract_key = None


class AdapterProcessor:
@staticmethod
Expand Down Expand Up @@ -91,6 +97,12 @@ def test_adapter(adapter_id: str, adapter_metadata: dict[str, Any]) -> bool:
adapter_class = Adapterkit().get_adapter_class_by_adapter_id(adapter_id)

if adapter_metadata.pop(AdapterKeys.ADAPTER_TYPE) == AdapterKeys.X2TEXT:

if (
adapter_metadata.get(AdapterKeys.PLATFORM_PROVIDED_UNSTRACT_KEY)
and add_unstract_key
):
adapter_metadata = add_unstract_key(adapter_metadata)
adapter_metadata[X2TextConstants.X2TEXT_HOST] = settings.X2TEXT_HOST
adapter_metadata[X2TextConstants.X2TEXT_PORT] = settings.X2TEXT_PORT
platform_key = PlatformAuthenticationService.get_active_platform_key()
Expand All @@ -106,6 +118,21 @@ def test_adapter(adapter_id: str, adapter_metadata: dict[str, Any]) -> bool:
e, adapter_name=adapter_metadata[AdapterKeys.ADAPTER_NAME]
)

@staticmethod
def update_adapter_metadata(adapter_metadata_b: Any) -> Any:
if add_unstract_key:
encryption_secret: str = settings.ENCRYPTION_KEY
f: Fernet = Fernet(encryption_secret.encode("utf-8"))

adapter_metadata = json.loads(
f.decrypt(bytes(adapter_metadata_b).decode("utf-8"))
)
adapter_metadata = add_unstract_key(adapter_metadata)

adapter_metadata_b = f.encrypt(json.dumps(adapter_metadata).encode("utf-8"))
return adapter_metadata_b
return adapter_metadata_b

@staticmethod
def __fetch_adapters_by_key_value(key: str, value: Any) -> Adapter:
"""Fetches a list of adapters that have an attribute matching key and
Expand Down
3 changes: 2 additions & 1 deletion backend/adapter_processor_v2/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ class AdapterKeys:
X2TEXT_DEFAULT = "x2text_default"
SHARED_USERS = "shared_users"
ADAPTER_NAME_EXISTS = (
"Configuration with this name already exists within your organisation. "
"Configuration with this name already exists within your organisation."
"Please try with a different name."
)
ADAPTER_NAME = "adapter_name"
ADAPTER_CREATED_BY = "created_by_email"
ADAPTER_CONTEXT_WINDOW_SIZE = "context_window_size"
PLATFORM_PROVIDED_UNSTRACT_KEY = "use_platform_provided_unstract_key"


class AllowedDomains(Enum):
Expand Down
23 changes: 22 additions & 1 deletion backend/adapter_processor_v2/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,30 @@ def get_serializer_class(

def create(self, request: Any) -> Response:
serializer = self.get_serializer(data=request.data)

use_platform_unstract_key = False
adapter_metadata = request.data.get(AdapterKeys.ADAPTER_METADATA)
if adapter_metadata and adapter_metadata.get(
AdapterKeys.PLATFORM_PROVIDED_UNSTRACT_KEY, False
):
use_platform_unstract_key = True

serializer.is_valid(raise_exception=True)
try:
adapter_type = serializer.validated_data.get(AdapterKeys.ADAPTER_TYPE)

if adapter_type == AdapterKeys.X2TEXT and use_platform_unstract_key:
adapter_metadata_b = serializer.validated_data.get(
AdapterKeys.ADAPTER_METADATA_B
)
adapter_metadata_b = AdapterProcessor.update_adapter_metadata(
adapter_metadata_b
)
# Update the validated data with the new adapter_metadata
serializer.validated_data[AdapterKeys.ADAPTER_METADATA_B] = (
adapter_metadata_b
)

instance = serializer.save()
organization_member = OrganizationMemberService.get_user_by_id(
request.user.id
Expand All @@ -185,7 +207,6 @@ def create(self, request: Any) -> Response:
organization_member=organization_member
)

adapter_type = serializer.validated_data.get(AdapterKeys.ADAPTER_TYPE)
if (adapter_type == AdapterKeys.LLM) and (
not user_default_adapter.default_llm_adapter
):
Expand Down
3 changes: 3 additions & 0 deletions backend/backend/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,9 @@ def get_required_setting(
# Whitelisting health check API
WHITELISTED_PATHS.append("/health")

# These path will work without organization in request
ORGANIZATION_MIDDLEWARE_WHITELISTED_PATHS = []

# API Doc Generator Settings
# https://drf-yasg.readthedocs.io/en/stable/settings.html
REDOC_SETTINGS = {
Expand Down
8 changes: 8 additions & 0 deletions backend/middleware/organization_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ def process_request(self, request):
# Check if the URL matches the pattern with organization ID
match = re.match(pattern, request.path)
if match:
# Check if the request path matches any of the whitelisted paths
if any(
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")
request.organization_id = org_id
new_path = re.sub(pattern, "/" + tenant_prefix, request.path_info)
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/hooks/useRequestUrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const useRequestUrl = () => {
const getUrl = (url) => {
if (!url) return null;

const baseUrl = `/api/v1/${sessionDetails?.orgId}/`;
const baseUrl = `/api/v1/unstract/${sessionDetails?.orgId}/`;
return baseUrl + url.replace(/^\//, "");
};

Expand Down
Loading