LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows
Python ai-agentsdata-engineeringdocument-aigenerative-aiidpjson-extractionllmmcp-serverocrpdf-extractionprompt-engineeringstructured-output
from workflow_manager.endpoint_v2.destination import DestinationConnector
from workflow_manager.endpoint_v2.models import WorkflowEndpoint
from workflow_manager.endpoint_v2.source import SourceConnector
from workflow_manager.workflow_v2.models.workflow import Workflow
from workflow_manager.workflow_v2.workflow_helper import WorkflowHelper
class WorkflowEndpointUtils:
@staticmethod
def create_endpoints_for_workflow(workflow: Workflow) -> None:
"""Create endpoints for a given workflow. This method creates both
source and destination endpoints for the specified workflow.
Parameters:
workflow (Workflow): The workflow for which
the endpoints need to be created.
Returns:
None
"""
SourceConnector.create_endpoint_for_workflow(workflow)
DestinationConnector.create_endpoint_for_workflow(workflow)
@staticmethod
def get_endpoint_for_workflow_by_type(
workflow_id: str, endpoint_type: WorkflowEndpoint.EndpointType
) -> WorkflowEndpoint:
"""Get endpoint for a given workflow by type.
Args:
workflow_id (str): The ID of the workflow.
endpoint_type (WorkflowEndpoint.EndpointType): The type of the endpoint.
Returns:
WorkflowEndpoint: The endpoint for the given workflow and type.
"""
workflow = WorkflowHelper.get_workflow_by_id(workflow_id)
endpoint: WorkflowEndpoint = WorkflowEndpoint.objects.get(
workflow=workflow,
endpoint_type=endpoint_type,
)
if endpoint.connector_instance:
endpoint.connector_instance.connector_metadata = (
endpoint.connector_instance.metadata
)
return endpoint
@staticmethod
def is_api_workflow(workflow: Workflow) -> bool:
"""Check if workflow uses API connectors for both source and destination.
Args:
workflow (Workflow): The workflow to check
Returns:
bool: True if both source and destination are API type, False otherwise
"""
try:
source_endpoint = WorkflowEndpoint.objects.get(
workflow=workflow,
endpoint_type=WorkflowEndpoint.EndpointType.SOURCE,
)
destination_endpoint = WorkflowEndpoint.objects.get(
workflow=workflow,
endpoint_type=WorkflowEndpoint.EndpointType.DESTINATION,
)
source_is_api = (
source_endpoint.connection_type == WorkflowEndpoint.ConnectionType.API
)
destination_is_api = (
destination_endpoint.connection_type
== WorkflowEndpoint.ConnectionType.API
)
return source_is_api and destination_is_api
except WorkflowEndpoint.DoesNotExist:
return False