Skip to content

LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows

minor additions from V1 on workflow executions. Table name changes in platform and prompt (#741)

ali81cea6b17a54
diff --git a/backend/tool_instance_v2/serializers.py b/backend/tool_instance_v2/serializers.py
index 48331dae2..bee77ccbb 100644
--- a/backend/tool_instance_v2/serializers.py
+++ b/backend/tool_instance_v2/serializers.py
@@ -68,7 +68,7 @@ class ToolInstanceSerializer(AuditSerializer):
raise ValidationError(f"Workflow with ID {workflow_id} does not exist.")
validated_data[TIKey.WORKFLOW] = workflow
- if workflow.workflow_tool.count() > 0:
+ if workflow.tool_instances.count() > 0:
raise ValidationError(
f"Workflow with ID {workflow_id} can't have more than one tool."
)
diff --git a/backend/workflow_manager/workflow_v2/execution.py b/backend/workflow_manager/workflow_v2/execution.py
index 84e2b51dc..3af07d748 100644
--- a/backend/workflow_manager/workflow_v2/execution.py
+++ b/backend/workflow_manager/workflow_v2/execution.py
@@ -34,7 +34,6 @@ class WorkflowExecutionServiceHelper(WorkflowExecutionService):
scheduled: bool = False,
mode: tuple[str, str] = WorkflowExecution.Mode.INSTANT,
workflow_execution: Optional[WorkflowExecution] = None,
- include_metadata: bool = False,
) -> None:
tool_instances_as_dto = []
for tool_instance in tool_instances:
@@ -210,7 +209,7 @@ class WorkflowExecutionServiceHelper(WorkflowExecutionService):
)
raise WorkflowExecutionError(self.compilation_result["problems"][0])
- def execute(self, single_step: bool = False) -> None:
+ def execute(self, run_id: str, file_name: str, single_step: bool = False) -> None:
execution_type = ExecutionType.COMPLETE
if single_step:
execution_type = ExecutionType.STEP
@@ -231,7 +230,9 @@ class WorkflowExecutionServiceHelper(WorkflowExecutionService):
start_time = time.time()
try:
- self.execute_workflow(execution_type=execution_type)
+ self.execute_workflow(
+ run_id=run_id, file_name=file_name, execution_type=execution_type
+ )
end_time = time.time()
execution_time = end_time - start_time
except StopExecution as exception:
@@ -302,30 +303,34 @@ class WorkflowExecutionServiceHelper(WorkflowExecutionService):
def execute_input_file(
self,
+ run_id: str,
file_name: str,
single_step: bool,
- ) -> tuple[bool, bool]:
+ ) -> None:
"""Executes the input file.
Args:
+ run_id (str): UUID for a single run of a file
file_name (str): The name of the file to be executed.
single_step (bool): Flag indicating whether to execute in
single step mode.
- Returns:
- tuple[bool, bool]: Flag indicating whether the file was executed
- and skipped.
"""
execution_type = ExecutionType.COMPLETE
if single_step:
execution_type = ExecutionType.STEP
- self.execute_uncached_input(file_name=file_name, single_step=single_step)
+ self.execute_uncached_input(
+ run_id=run_id, file_name=file_name, single_step=single_step
+ )
self.publish_log(f"Tool executed successfully for '{file_name}'")
self._handle_execution_type(execution_type)
- def execute_uncached_input(self, file_name: str, single_step: bool) -> None:
+ def execute_uncached_input(
+ self, run_id: str, file_name: str, single_step: bool
+ ) -> None:
"""Executes the uncached input file.
Args:
+ run_id (str): UUID for a single run of a file
file_name (str): The name of the file to be executed.
single_step (bool): Flag indicating whether to execute in
single step mode.
@@ -333,13 +338,16 @@ class WorkflowExecutionServiceHelper(WorkflowExecutionService):
Returns:
None
"""
- self.publish_log("No entries found in cache, executing the tools")
+ self.publish_log(
+ "No entries found in cache, executing the tools"
+ f"running the tool(s) for {file_name}"
+ )
self.publish_update_log(
state=LogState.SUCCESS,
message=f"{file_name} Sent for execution",
component=LogComponent.SOURCE,
)
- self.execute(single_step)
+ self.execute(run_id, file_name, single_step)
def initiate_tool_execution(
self,
diff --git a/backend/workflow_manager/workflow_v2/views.py b/backend/workflow_manager/workflow_v2/views.py
index 97b504f3c..3d37da92e 100644
--- a/backend/workflow_manager/workflow_v2/views.py
+++ b/backend/workflow_manager/workflow_v2/views.py
@@ -15,17 +15,20 @@ from tool_instance_v2.tool_processor import ToolProcessor
from unstract.tool_registry.dto import Tool
from utils.filtering import FilterHelper
from workflow_manager.endpoint_v2.destination import DestinationConnector
+from workflow_manager.endpoint_v2.dto import FileHash
from workflow_manager.endpoint_v2.endpoint_utils import WorkflowEndpointUtils
from workflow_manager.endpoint_v2.source import SourceConnector
from workflow_manager.workflow_v2.constants import WorkflowKey
from workflow_manager.workflow_v2.dto import ExecutionResponse
from workflow_manager.workflow_v2.enums import SchemaEntity, SchemaType
from workflow_manager.workflow_v2.exceptions import (
+ InternalException,
WorkflowDoesNotExistError,
WorkflowGenerationError,
WorkflowRegenerationError,
)
from workflow_manager.workflow_v2.generator import WorkflowGenerator
+from workflow_manager.workflow_v2.models.execution import WorkflowExecution
from workflow_manager.workflow_v2.models.workflow import Workflow
from workflow_manager.workflow_v2.serializers import (
ExecuteWorkflowResponseSerializer,
@@ -91,6 +94,7 @@ class WorkflowViewSet(viewsets.ModelViewSet):
Raises: WorkflowGenerationError
"""
kwargs = {}
+
try:
workflow = serializer.save(**kwargs)
return workflow
@@ -157,10 +161,7 @@ class WorkflowViewSet(viewsets.ModelViewSet):
execution_id = serializer.get_execution_id(serializer.validated_data)
execution_action = serializer.get_execution_action(serializer.validated_data)
file_objs = request.FILES.getlist("files")
- include_metadata = (
- request.data.get("include_metadata", "false").lower() == "true"
- )
- hashes_of_files = {}
+ hashes_of_files: dict[str, FileHash] = {}
if file_objs and execution_id and workflow_id:
hashes_of_files = SourceConnector.add_input_file_to_api_storage(
workflow_id=workflow_id,
@@ -178,8 +179,13 @@ class WorkflowViewSet(viewsets.ModelViewSet):
execution_id=execution_id,
pipeline_guid=pipeline_guid,
hash_values_of_files=hashes_of_files,
- include_metadata=include_metadata,
)
+ if (
+ execution_response.execution_status == "ERROR"
+ and execution_response.result
+ and execution_response.result[0].get("error")
+ ):
+ raise InternalException(execution_response.result[0].get("error"))
return Response(
make_execution_response(execution_response),
status=status.HTTP_200_OK,
@@ -198,8 +204,7 @@ class WorkflowViewSet(viewsets.ModelViewSet):
execution_action: Optional[str] = None,
execution_id: Optional[str] = None,
pipeline_guid: Optional[str] = None,
- hash_values_of_files: dict[str, str] = {},
- include_metadata: bool = False,
+ hash_values_of_files: dict[str, FileHash] = {},
) -> ExecutionResponse:
if execution_action is not None:
# Step execution
@@ -208,7 +213,6 @@ class WorkflowViewSet(viewsets.ModelViewSet):
execution_action,
execution_id=execution_id,
hash_values_of_files=hash_values_of_files,
- include_metadata=include_metadata,
)
elif pipeline_guid:
# pipeline execution
@@ -219,14 +223,15 @@ class WorkflowViewSet(viewsets.ModelViewSet):
workflow=workflow,
execution_id=execution_id,
pipeline_id=pipeline_guid,
+ execution_mode=WorkflowExecution.Mode.INSTANT,
hash_values_of_files=hash_values_of_files,
)
else:
execution_response = WorkflowHelper.complete_execution(
workflow=workflow,
execution_id=execution_id,
+ execution_mode=WorkflowExecution.Mode.INSTANT,
hash_values_of_files=hash_values_of_files,
- include_metadata=include_metadata,
)
return execution_response
diff --git a/backend/workflow_manager/workflow_v2/workflow_helper.py b/backend/workflow_manager/workflow_v2/workflow_helper.py
index 01c2e1e62..0ac9b79ec 100644
--- a/backend/workflow_manager/workflow_v2/workflow_helper.py
+++ b/backend/workflow_manager/workflow_v2/workflow_helper.py
@@ -3,6 +3,7 @@ import logging
import os
import traceback
from typing import Any, Optional
+from uuid import uuid4
from account_v2.constants import Common
from api_v2.models import APIDeployment
@@ -156,6 +157,7 @@ class WorkflowHelper:
except Exception as e:
failed_files += 1
error_message = f"Error processing file '{file_path}'. {e}"
+ logger.error(error_message, stack_info=True, exc_info=True)
execution_service.publish_log(
message=error_message, level=LogLevel.ERROR
)
@@ -194,7 +196,11 @@ class WorkflowHelper:
current_file_idx, total_files, file_name, single_step
)
if not file_hash.is_executed:
+ # Multiple run_ids are linked to an execution_id
+ # Each run_id corresponds to workflow runs for a single file
+ run_id = str(uuid4())
execution_service.execute_input_file(
+ run_id=run_id,
file_name=file_name,
single_step=single_step,
)
@@ -547,6 +553,10 @@ class WorkflowHelper:
dict[str, list[Any]]: Returns a dict with result from
workflow execution
"""
+ hash_values = {
+ key: FileHash.from_json(value)
+ for key, value in hash_values_of_files.items()
+ }
workflow = Workflow.objects.get(id=workflow_id)
try:
workflow_execution = (
@@ -573,7 +583,7 @@ class WorkflowHelper:
scheduled=scheduled,
workflow_execution=workflow_execution,
execution_mode=execution_mode,
- hash_values_of_files=hash_values_of_files,
+ hash_values_of_files=hash_values,
)
except Exception as error:
error_message = traceback.format_exc()
@@ -682,8 +692,7 @@ class WorkflowHelper:
workflow: Workflow,
execution_action: str,
execution_id: Optional[str] = None,
- hash_values_of_files: dict[str, str] = {},
- include_metadata: bool = False,
+ hash_values_of_files: dict[str, FileHash] = {},
) -> ExecutionResponse:
if execution_action is Workflow.ExecutionAction.START.value: # type: ignore
if execution_id is None:
@@ -697,7 +706,6 @@ class WorkflowHelper:
single_step=True,
workflow_execution=workflow_execution,
hash_values_of_files=hash_values_of_files,
- include_metadata=include_metadata,
)
except WorkflowExecution.DoesNotExist:
return WorkflowHelper.create_and_make_execution_response(
diff --git a/platform-service/src/unstract/platform_service/constants.py b/platform-service/src/unstract/platform_service/constants.py
index 75fcbf0da..a9f87437f 100644
--- a/platform-service/src/unstract/platform_service/constants.py
+++ b/platform-service/src/unstract/platform_service/constants.py
@@ -13,11 +13,11 @@ class DBTable:
class DBTableV2:
"""Database tables."""
- ORGANIZATION = "organization_v2"
- ADAPTER_INSTANCE = "adapter_instance_v2"
- PROMPT_STUDIO_REGISTRY = "prompt_studio_registry_v2"
- PLATFORM_KEY = "platform_key_v2"
- TOKEN_USAGE = "token_usage_v2"
+ ORGANIZATION = "organization"
+ ADAPTER_INSTANCE = "adapter_instance"
+ PROMPT_STUDIO_REGISTRY = "prompt_studio_registry"
+ PLATFORM_KEY = "platform_key"
+ TOKEN_USAGE = "usage"
class LogLevel:
diff --git a/prompt-service/src/unstract/prompt_service/constants.py b/prompt-service/src/unstract/prompt_service/constants.py
index 20f0f0b18..f5ee6f2e0 100644
--- a/prompt-service/src/unstract/prompt_service/constants.py
+++ b/prompt-service/src/unstract/prompt_service/constants.py
@@ -98,8 +98,8 @@ class FeatureFlag:
class DBTableV2:
"""Database tables."""
- ORGANIZATION = "organization_v2"
- ADAPTER_INSTANCE = "adapter_instance_v2"
- PROMPT_STUDIO_REGISTRY = "prompt_studio_registry_v2"
- PLATFORM_KEY = "platform_key_v2"
- TOKEN_USAGE = "token_usage_v2"
+ ORGANIZATION = "organization"
+ ADAPTER_INSTANCE = "adapter_instance"
+ PROMPT_STUDIO_REGISTRY = "prompt_studio_registry"
+ PLATFORM_KEY = "platform_key"
+ TOKEN_USAGE = "usage"