Skip to content

Commit 41d8031

Browse files
Merge branch 'main' into fix/UserExistValidation
2 parents 695f19b + 2f84d14 commit 41d8031

File tree

24 files changed

+1111
-968
lines changed

24 files changed

+1111
-968
lines changed

backend/api_v2/api_deployment_views.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def post(
5252
serializer.is_valid(raise_exception=True)
5353
timeout = serializer.validated_data.get(ApiExecution.TIMEOUT_FORM_DATA)
5454
include_metadata = serializer.validated_data.get(ApiExecution.INCLUDE_METADATA)
55+
include_metrics = serializer.validated_data.get(ApiExecution.INCLUDE_METRICS)
5556
use_file_history = serializer.validated_data.get(ApiExecution.USE_FILE_HISTORY)
5657
if not file_objs or len(file_objs) == 0:
5758
raise InvalidAPIRequest("File shouldn't be empty")
@@ -61,6 +62,7 @@ def post(
6162
file_objs=file_objs,
6263
timeout=timeout,
6364
include_metadata=include_metadata,
65+
include_metrics=include_metrics,
6466
use_file_history=use_file_history,
6567
)
6668
if "error" in response and response["error"]:
@@ -79,6 +81,7 @@ def get(
7981

8082
execution_id = serializer.validated_data.get(ApiExecution.EXECUTION_ID)
8183
include_metadata = serializer.validated_data.get(ApiExecution.INCLUDE_METADATA)
84+
include_metrics = serializer.validated_data.get(ApiExecution.INCLUDE_METRICS)
8285

8386
# Fetch execution status
8487
response: ExecutionResponse = DeploymentHelper.get_execution_status(
@@ -91,6 +94,8 @@ def get(
9194
response_status = status.HTTP_200_OK
9295
if not include_metadata:
9396
response.remove_result_metadata_keys()
97+
if not include_metrics:
98+
response.remove_result_metrics()
9499
if response.result_acknowledged:
95100
response_status = status.HTTP_406_NOT_ACCEPTABLE
96101
response.result = "Result already acknowledged"

backend/api_v2/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ class ApiExecution:
44
FILES_FORM_DATA: str = "files"
55
TIMEOUT_FORM_DATA: str = "timeout"
66
INCLUDE_METADATA: str = "include_metadata"
7+
INCLUDE_METRICS: str = "include_metrics"
78
USE_FILE_HISTORY: str = "use_file_history" # Undocumented parameter
89
EXECUTION_ID: str = "execution_id"

backend/api_v2/deployment_helper.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ def execute_workflow(
136136
file_objs: list[UploadedFile],
137137
timeout: int,
138138
include_metadata: bool = False,
139+
include_metrics: bool = False,
139140
use_file_history: bool = False,
140141
) -> ReturnDict:
141142
"""Execute workflow by api.
@@ -180,6 +181,8 @@ def execute_workflow(
180181
)
181182
if not include_metadata:
182183
result.remove_result_metadata_keys()
184+
if not include_metrics:
185+
result.remove_result_metrics()
183186
except Exception as error:
184187
DestinationConnector.delete_api_storage_dir(
185188
workflow_id=workflow_id, execution_id=execution_id

backend/api_v2/postman_collection/dto.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ def get_form_data_items(self) -> list[FormDataItem]:
118118
value=ApiExecution.MAXIMUM_TIMEOUT_IN_SEC,
119119
),
120120
FormDataItem(key=ApiExecution.INCLUDE_METADATA, type="text", value="False"),
121+
FormDataItem(key=ApiExecution.INCLUDE_METRICS, type="text", value="False"),
121122
]
122123

123124
def get_api_key(self) -> str:
@@ -131,6 +132,7 @@ def _get_status_api_request(self) -> RequestItem:
131132
status_query_param = {
132133
"execution_id": CollectionKey.STATUS_EXEC_ID_DEFAULT,
133134
ApiExecution.INCLUDE_METADATA: "False",
135+
ApiExecution.INCLUDE_METRICS: "False",
134136
}
135137
status_query_str = urlencode(status_query_param)
136138
abs_api_endpoint = urljoin(settings.WEB_APP_ORIGIN_URL, self.api_endpoint)

backend/api_v2/serializers.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ class ExecutionRequestSerializer(Serializer):
106106
timeout (int): Timeout for the API deployment, maximum value can be 300s.
107107
If -1 it corresponds to async execution. Defaults to -1
108108
include_metadata (bool): Flag to include metadata in API response
109+
include_metrics (bool): Flag to include metrics in API response
109110
use_file_history (bool): Flag to use FileHistory to save and retrieve
110111
responses quickly. This is undocumented to the user and can be
111112
helpful for demos.
@@ -115,12 +116,14 @@ class ExecutionRequestSerializer(Serializer):
115116
min_value=-1, max_value=ApiExecution.MAXIMUM_TIMEOUT_IN_SEC, default=-1
116117
)
117118
include_metadata = BooleanField(default=False)
119+
include_metrics = BooleanField(default=False)
118120
use_file_history = BooleanField(default=False)
119121

120122

121123
class ExecutionQuerySerializer(Serializer):
122124
execution_id = CharField(required=True)
123125
include_metadata = BooleanField(default=False)
126+
include_metrics = BooleanField(default=False)
124127

125128
def validate_execution_id(self, value):
126129
"""Trim spaces, validate UUID format, and check if execution_id exists."""

backend/pdm.lock

Lines changed: 40 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ dependencies = [
3232
"python-socketio==5.9.0", # For log_events
3333
"social-auth-app-django==5.3.0", # For OAuth
3434
"social-auth-core==4.4.2", # For OAuth
35-
"unstract-sdk~=0.54.0rc6",
35+
"unstract-sdk~=0.54.0rc8",
3636
# ! IMPORTANT!
3737
# Indirect local dependencies usually need to be added in their own projects
3838
# as: https://pdm-project.org/latest/usage/dependency/#local-dependencies.

backend/sample.env

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ REMOTE_PROMPT_STUDIO_FILE_PATH=
8282

8383
# Structure Tool Image (Runs prompt studio exported tools)
8484
# https://hub.docker.com/r/unstract/tool-structure
85-
STRUCTURE_TOOL_IMAGE_URL="docker:unstract/tool-structure:0.0.52"
85+
STRUCTURE_TOOL_IMAGE_URL="docker:unstract/tool-structure:0.0.53"
8686
STRUCTURE_TOOL_IMAGE_NAME="unstract/tool-structure"
87-
STRUCTURE_TOOL_IMAGE_TAG="0.0.52"
87+
STRUCTURE_TOOL_IMAGE_TAG="0.0.53"
8888

8989
# Feature Flags
9090
EVALUATION_SERVER_IP=unstract-flipt

backend/workflow_manager/workflow_v2/dto.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,21 @@ def remove_result_metadata_keys(self, keys_to_remove: list[str] = []) -> None:
6363

6464
self._remove_specific_keys(result=result, keys_to_remove=keys_to_remove)
6565

66+
def remove_result_metrics(self) -> None:
67+
"""Removes the 'metrics' key from the 'result' dictionary within each
68+
'result' dictionary in the 'result' list attribute of the instance.
69+
"""
70+
if not isinstance(self.result, list):
71+
return
72+
73+
for item in self.result:
74+
if not isinstance(item, dict):
75+
continue
76+
77+
result = item.get("result")
78+
if isinstance(result, dict):
79+
result.pop("metrics", None)
80+
6681
def _remove_specific_keys(self, result: dict, keys_to_remove: list[str]) -> None:
6782
"""Removes specified keys from the 'metadata' dictionary within the
6883
provided 'result' dictionary. If 'keys_to_remove' is empty, the

0 commit comments

Comments
 (0)