Skip to content

Commit 6c17c00

Browse files
Merge branch 'feat/UN-3011-FEAT_limit_maximum_file_execution_count_with_file_history_viewer' of github.com:Zipstack/unstract into feat/UN-3011-FEAT_limit_maximum_file_execution_count_with_file_history_viewer
2 parents d14aa46 + a6886f5 commit 6c17c00

File tree

157 files changed

+9544
-14715
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

157 files changed

+9544
-14715
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,11 @@ $RECYCLE.BIN/
623623
# BE pluggable-apps
624624
backend/pluggable_apps/*
625625

626+
# Workers pluggable workers (cloud-only) - ignore all except structure files
627+
workers/pluggable_worker/*
628+
!workers/pluggable_worker/__init__.py
629+
!workers/pluggable_worker/README.md
630+
626631
# FE Plugins
627632
frontend/src/plugins/*
628633
frontend/public/llm-whisperer/

backend/adapter_processor_v2/adapter_processor.py

Lines changed: 42 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,13 @@
1616
InValidAdapterId,
1717
TestAdapterError,
1818
)
19-
from unstract.flags.feature_flag import check_feature_flag_status
20-
21-
if check_feature_flag_status("sdk1"):
22-
from unstract.sdk1.adapters.adapterkit import Adapterkit
23-
from unstract.sdk1.adapters.base import Adapter
24-
from unstract.sdk1.constants import AdapterTypes
25-
from unstract.sdk1.embedding import EmbeddingCompat
26-
from unstract.sdk1.exceptions import SdkError
27-
from unstract.sdk1.llm import LLM
28-
else:
29-
from unstract.sdk.adapters.adapterkit import Adapterkit
30-
from unstract.sdk.adapters.base import Adapter
31-
from unstract.sdk.adapters.enums import AdapterTypes
32-
from unstract.sdk.adapters.x2text.constants import X2TextConstants
33-
from unstract.sdk.exceptions import SdkError
19+
from unstract.sdk1.adapters.adapterkit import Adapterkit
20+
from unstract.sdk1.adapters.base import Adapter
21+
from unstract.sdk1.adapters.x2text.constants import X2TextConstants
22+
from unstract.sdk1.constants import AdapterTypes
23+
from unstract.sdk1.embedding import EmbeddingCompat
24+
from unstract.sdk1.exceptions import SdkError
25+
from unstract.sdk1.llm import LLM
3426

3527
from .models import AdapterInstance, UserDefaultAdapter
3628

@@ -89,66 +81,47 @@ def get_all_supported_adapters(user_email: str, type: str) -> list[dict[Any, Any
8981

9082
@staticmethod
9183
def get_adapter_data_with_key(adapter_id: str, key_value: str) -> Any:
92-
"""Generic Function to get adapter data with provided key."""
84+
"""Generic Function to get adapter data with provided key.
85+
86+
Args:
87+
adapter_id: The SDK identifier for the adapter
88+
key_value: The key to retrieve from adapter data
89+
90+
Returns:
91+
The value associated with the key
92+
93+
Raises:
94+
InValidAdapterId: If adapter is not found in SDK
95+
96+
Note:
97+
For deprecated adapters (not in SDK), this will raise InValidAdapterId.
98+
Callers should handle this gracefully by checking is_available field first.
99+
"""
93100
updated_adapters = AdapterProcessor.__fetch_adapters_by_key_value(
94101
"id", adapter_id
95102
)
96103
if len(updated_adapters) == 0:
97-
logger.error(f"Invalid adapter ID {adapter_id} while invoking utility")
104+
logger.warning(
105+
f"Adapter ID {adapter_id} not found in SDK. "
106+
"This may be a deprecated adapter that was removed from SDK."
107+
)
98108
raise InValidAdapterId()
99109
return updated_adapters[0].get(key_value)
100110

101111
@staticmethod
102112
def test_adapter(adapter_id: str, adapter_metadata: dict[str, Any]) -> bool:
103-
if check_feature_flag_status("sdk1"):
104-
try:
105-
adapter_type = adapter_metadata.get(AdapterKeys.ADAPTER_TYPE)
106-
107-
if adapter_type == AdapterKeys.EMBEDDING:
108-
embedding = EmbeddingCompat(
109-
adapter_id=adapter_id, adapter_metadata=adapter_metadata
110-
)
111-
return embedding.test_connection()
112-
elif adapter_type == AdapterKeys.LLM:
113-
llm = LLM(adapter_id=adapter_id, adapter_metadata=adapter_metadata)
114-
return llm.test_connection()
115-
else:
116-
adapter_class = Adapterkit().get_adapter_class_by_adapter_id(
117-
adapter_id
118-
)
113+
try:
114+
adapter_type = adapter_metadata.get(AdapterKeys.ADAPTER_TYPE)
119115

120-
if (
121-
adapter_metadata.pop(AdapterKeys.ADAPTER_TYPE)
122-
== AdapterKeys.X2TEXT
123-
):
124-
if (
125-
adapter_metadata.get(
126-
AdapterKeys.PLATFORM_PROVIDED_UNSTRACT_KEY
127-
)
128-
and add_unstract_key
129-
):
130-
adapter_metadata = add_unstract_key(adapter_metadata)
131-
adapter_metadata[X2TextConstants.X2TEXT_HOST] = (
132-
settings.X2TEXT_HOST
133-
)
134-
adapter_metadata[X2TextConstants.X2TEXT_PORT] = (
135-
settings.X2TEXT_PORT
136-
)
137-
platform_key = (
138-
PlatformAuthenticationService.get_active_platform_key()
139-
)
140-
adapter_metadata[X2TextConstants.PLATFORM_SERVICE_API_KEY] = str(
141-
platform_key.key
142-
)
143-
144-
adapter_instance = adapter_class(adapter_metadata)
145-
return adapter_instance.test_connection()
146-
except SdkError as e:
147-
raise TestAdapterError(
148-
e, adapter_name=adapter_metadata[AdapterKeys.ADAPTER_NAME]
116+
if adapter_type == AdapterKeys.EMBEDDING:
117+
embedding = EmbeddingCompat(
118+
adapter_id=adapter_id, adapter_metadata=adapter_metadata
149119
)
150-
else:
151-
try:
120+
return embedding.test_connection()
121+
elif adapter_type == AdapterKeys.LLM:
122+
llm = LLM(adapter_id=adapter_id, adapter_metadata=adapter_metadata)
123+
return llm.test_connection()
124+
else:
152125
adapter_class = Adapterkit().get_adapter_class_by_adapter_id(adapter_id)
153126

154127
if adapter_metadata.pop(AdapterKeys.ADAPTER_TYPE) == AdapterKeys.X2TEXT:
@@ -165,12 +138,11 @@ def test_adapter(adapter_id: str, adapter_metadata: dict[str, Any]) -> bool:
165138
)
166139

167140
adapter_instance = adapter_class(adapter_metadata)
168-
test_result: bool = adapter_instance.test_connection()
169-
return test_result
170-
except SdkError as e:
171-
raise TestAdapterError(
172-
e, adapter_name=adapter_metadata[AdapterKeys.ADAPTER_NAME]
173-
)
141+
return adapter_instance.test_connection()
142+
except SdkError as e:
143+
raise TestAdapterError(
144+
e, adapter_name=adapter_metadata[AdapterKeys.ADAPTER_NAME]
145+
) from e
174146

175147
@staticmethod
176148
def update_adapter_metadata(adapter_metadata_b: Any, **kwargs) -> Any:

backend/adapter_processor_v2/constants.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ class AdapterKeys:
3131
ADAPTER_CREATED_BY = "created_by_email"
3232
ADAPTER_CONTEXT_WINDOW_SIZE = "context_window_size"
3333
PLATFORM_PROVIDED_UNSTRACT_KEY = "use_platform_provided_unstract_key"
34+
IS_AVAILABLE = "is_available"
35+
DEPRECATION_METADATA = "deprecation_metadata"
36+
IS_DEPRECATED = "is_deprecated"
3437

3538

3639
class AllowedDomains(Enum):

backend/adapter_processor_v2/exceptions.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
from rest_framework.exceptions import APIException
22

33
from adapter_processor_v2.constants import AdapterKeys
4-
from unstract.flags.feature_flag import check_feature_flag_status
5-
6-
if check_feature_flag_status("sdk1"):
7-
from unstract.sdk1.exceptions import SdkError
8-
else:
9-
from unstract.sdk.exceptions import SdkError
4+
from unstract.sdk1.exceptions import SdkError
105

116

127
class IdIsMandatory(APIException):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Management package for adapter_processor_v2
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Management commands for adapter_processor_v2

0 commit comments

Comments
 (0)