LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows
Python ai-agentsdata-engineeringdocument-aigenerative-aiidpjson-extractionllmmcp-serverocrpdf-extractionprompt-engineeringstructured-output
Api fixes for V2 (#777)
alid52a05396786
diff --git a/backend/api_v2/api_deployment_views.py b/backend/api_v2/api_deployment_views.pyindex 6530877d2..18654bb6d 100644--- a/backend/api_v2/api_deployment_views.py+++ b/backend/api_v2/api_deployment_views.py@@ -121,7 +121,9 @@ class APIDeploymentViewSet(viewsets.ModelViewSet):serializer: Serializer = self.get_serializer(data=request.data)serializer.is_valid(raise_exception=True)self.perform_create(serializer)- api_key = DeploymentHelper.create_api_key(serializer=serializer)+ api_key = DeploymentHelper.create_api_key(+ serializer=serializer, request=request+ )response_serializer = DeploymentResponseSerializer({"api_key": api_key.api_key, **serializer.data})diff --git a/backend/api_v2/deployment_helper.py b/backend/api_v2/deployment_helper.pyindex 9dc0488fb..149f38e1b 100644--- a/backend/api_v2/deployment_helper.py+++ b/backend/api_v2/deployment_helper.py@@ -109,7 +109,7 @@ class DeploymentHelper(BaseAPIKeyValidator):return None@staticmethod- def create_api_key(serializer: Serializer) -> APIKey:+ def create_api_key(serializer: Serializer, request: Request) -> APIKey:"""To make API key for an API.Args:@@ -120,7 +120,7 @@ class DeploymentHelper(BaseAPIKeyValidator):"""api_deployment: APIDeployment = serializer.instancetry:- api_key: APIKey = KeyHelper.create_api_key(api_deployment)+ api_key: APIKey = KeyHelper.create_api_key(api_deployment, request)return api_keyexcept Exception as error:logger.error(f"Error while creating API key error: {str(error)}")diff --git a/backend/api_v2/key_helper.py b/backend/api_v2/key_helper.pyindex 15d285ac3..2ff10654c 100644--- a/backend/api_v2/key_helper.py+++ b/backend/api_v2/key_helper.py@@ -5,6 +5,7 @@ from api_v2.exceptions import UnauthorizedKeyfrom api_v2.models import APIDeployment, APIKeyfrom api_v2.serializers import APIKeySerializerfrom pipeline_v2.models import Pipeline+from rest_framework.request import Requestfrom workflow_manager.workflow_v2.workflow_helper import WorkflowHelperlogger = logging.getLogger(__name__)@@ -68,12 +69,14 @@ class KeyHelper:WorkflowHelper.get_workflow_by_id(workflow_id)@staticmethod- def create_api_key(deployment: Union[APIDeployment, Pipeline]) -> APIKey:+ def create_api_key(+ deployment: Union[APIDeployment, Pipeline], request: Request+ ) -> APIKey:"""Create an APIKey entity using the data from the providedAPIDeployment or Pipeline instance."""api_key_serializer = APIKeySerializer(data=deployment.api_key_data,- context={"deployment": deployment},+ context={"deployment": deployment, "request": request},)api_key_serializer.is_valid(raise_exception=True)api_key: APIKey = api_key_serializer.save()diff --git a/backend/api_v2/models.py b/backend/api_v2/models.pyindex 28aef3ff5..c9a58eb8a 100644--- a/backend/api_v2/models.py+++ b/backend/api_v2/models.py@@ -175,7 +175,16 @@ class APIKey(BaseModel):)def __str__(self) -> str:- return f"{self.api.api_name} - {self.id} - {self.api_key}"+ if self.api:+ api_name = self.api.api_name+ elif self.pipeline:+ api_name = self.pipeline.pipeline_name+ else:+ api_name = None++ api_key = self.api_key if self.api_key else None++ return f"{api_name} - {self.id} - {api_key}"class Meta:verbose_name = "Api Deployment key"diff --git a/backend/api_v2/serializers.py b/backend/api_v2/serializers.pyindex 4c9a85318..655478e4b 100644--- a/backend/api_v2/serializers.py+++ b/backend/api_v2/serializers.py@@ -144,6 +144,7 @@ class APIKeyListSerializer(ModelSerializer):"is_active","description","api",+ "pipeline",]diff --git a/backend/backend/base_urls.py b/backend/backend/base_urls.pyindex b0c728867..1d235aad6 100644--- a/backend/backend/base_urls.py+++ b/backend/backend/base_urls.py@@ -18,4 +18,8 @@ urlpatterns = [),# API deploymentpath(f"{settings.API_DEPLOYMENT_PATH_PREFIX}/", include("api_v2.execution_urls")),+ path(+ f"{settings.API_DEPLOYMENT_PATH_PREFIX}/pipeline/",+ include("pipeline_v2.public_api_urls"),+ ),]diff --git a/backend/pipeline_v2/deployment_helper.py b/backend/pipeline_v2/deployment_helper.pyindex f50fd9b3c..6a0413629 100644--- a/backend/pipeline_v2/deployment_helper.py+++ b/backend/pipeline_v2/deployment_helper.py@@ -7,6 +7,7 @@ from api_v2.key_helper import KeyHelperfrom pipeline_v2.exceptions import PipelineNotFoundfrom pipeline_v2.pipeline_processor import PipelineProcessorfrom rest_framework.request import Request+from utils.user_context import UserContextlogger = logging.getLogger(__name__)@@ -16,8 +17,12 @@ class DeploymentHelper(BaseAPIKeyValidator):def validate_parameters(request: Request, **kwargs: Any) -> None:"""Validate pipeline_id for pipeline deployments."""pipeline_id = kwargs.get("pipeline_id") or request.data.get("pipeline_id")+ org_name = kwargs.get("org_name") or request.data.get("org_name")if not pipeline_id:raise InvalidAPIRequest("Missing params pipeline_id")+ if not org_name:+ raise InvalidAPIRequest("Missing params org_name")+ UserContext.set_organization_identifier(org_name)@staticmethoddef validate_and_process(diff --git a/backend/pipeline_v2/views.py b/backend/pipeline_v2/views.pyindex fecc23163..1d13e4381 100644--- a/backend/pipeline_v2/views.py+++ b/backend/pipeline_v2/views.py@@ -85,7 +85,7 @@ class PipelineViewSet(viewsets.ModelViewSet):try:pipeline_instance = serializer.save()# Create API key using the created instance- KeyHelper.create_api_key(pipeline_instance)+ KeyHelper.create_api_key(pipeline_instance, request)except IntegrityError:raise DuplicateData(f"{PipelineErrors.PIPELINE_EXISTS}, " f"{PipelineErrors.DUPLICATE_API}"