Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introdocing tag model and tag added in executions #1085

Merged
merged 16 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions backend/api_v2/api_deployment_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def post(
include_metadata = serializer.validated_data.get(ApiExecution.INCLUDE_METADATA)
include_metrics = serializer.validated_data.get(ApiExecution.INCLUDE_METRICS)
use_file_history = serializer.validated_data.get(ApiExecution.USE_FILE_HISTORY)
tag_names = serializer.validated_data.get(ApiExecution.TAGS)
if not file_objs or len(file_objs) == 0:
raise InvalidAPIRequest("File shouldn't be empty")
response = DeploymentHelper.execute_workflow(
Expand All @@ -64,6 +65,7 @@ def post(
include_metadata=include_metadata,
include_metrics=include_metrics,
use_file_history=use_file_history,
tag_names=tag_names,
)
if "error" in response and response["error"]:
return Response(
Expand Down
1 change: 1 addition & 0 deletions backend/api_v2/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ class ApiExecution:
INCLUDE_METRICS: str = "include_metrics"
USE_FILE_HISTORY: str = "use_file_history" # Undocumented parameter
EXECUTION_ID: str = "execution_id"
TAGS: str = "tags"
5 changes: 5 additions & 0 deletions backend/api_v2/deployment_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from rest_framework.request import Request
from rest_framework.serializers import Serializer
from rest_framework.utils.serializer_helpers import ReturnDict
from tags.models import Tag
from utils.constants import Account, CeleryQueue
from utils.local_context import StateStore
from workflow_manager.endpoint_v2.destination import DestinationConnector
Expand Down Expand Up @@ -138,6 +139,7 @@ def execute_workflow(
include_metadata: bool = False,
include_metrics: bool = False,
use_file_history: bool = False,
tag_names: list[str] = [],
) -> ReturnDict:
"""Execute workflow by api.

Expand All @@ -147,16 +149,19 @@ def execute_workflow(
file_obj (UploadedFile): input file
use_file_history (bool): Use FileHistory table to return results on already
processed files. Defaults to False
tag_names (list(str)): list of tag names

Returns:
ReturnDict: execution status/ result
"""
workflow_id = api.workflow.id
pipeline_id = api.id
tags = Tag.bulk_get_or_create(tag_names=tag_names)
workflow_execution = WorkflowExecutionServiceHelper.create_workflow_execution(
workflow_id=workflow_id,
pipeline_id=pipeline_id,
mode=WorkflowExecution.Mode.QUEUE,
tags=tags,
)
execution_id = workflow_execution.id

Expand Down
5 changes: 4 additions & 1 deletion backend/api_v2/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
Serializer,
ValidationError,
)
from tags.serializers import TagParamsSerializer
from utils.serializer.integrity_error_mixin import IntegrityErrorMixin
from workflow_manager.workflow_v2.exceptions import ExecutionDoesNotExistError
from workflow_manager.workflow_v2.models.execution import WorkflowExecution
Expand Down Expand Up @@ -99,7 +100,7 @@ def to_representation(self, instance: APIKey) -> OrderedDict[str, Any]:
return representation


class ExecutionRequestSerializer(Serializer):
class ExecutionRequestSerializer(TagParamsSerializer):
"""Execution request serializer.

Attributes:
Expand All @@ -110,6 +111,8 @@ class ExecutionRequestSerializer(Serializer):
use_file_history (bool): Flag to use FileHistory to save and retrieve
responses quickly. This is undocumented to the user and can be
helpful for demos.
tags (str): Comma-separated List of tags to associate with the execution.
e.g:'tag1,tag2-name,tag3_name'
"""

timeout = IntegerField(
Expand Down
9 changes: 6 additions & 3 deletions backend/backend/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ def get_required_setting(
"django.contrib.messages",
"django.contrib.staticfiles",
"django.contrib.admindocs",
"django_filters",
# Third party apps should go below this line,
"rest_framework",
# Connector OAuth
Expand All @@ -226,8 +227,6 @@ def get_required_setting(
"commands",
# health checks
"health",
)
v2_apps = (
"migrating.v2",
"connector_auth_v2",
"tenant_account_v2",
Expand All @@ -250,8 +249,8 @@ def get_required_setting(
"prompt_studio.prompt_studio_output_manager_v2",
"prompt_studio.prompt_studio_document_manager_v2",
"prompt_studio.prompt_studio_index_manager_v2",
"tags",
)
SHARED_APPS += v2_apps
TENANT_APPS = []

INSTALLED_APPS = list(SHARED_APPS) + [
Expand Down Expand Up @@ -432,6 +431,10 @@ def get_required_setting(
"DEFAULT_PERMISSION_CLASSES": [], # TODO: Update once auth is figured
"TEST_REQUEST_DEFAULT_FORMAT": "json",
"EXCEPTION_HANDLER": "middleware.exception.drf_logging_exc_handler",
"DEFAULT_FILTER_BACKENDS": [
"django_filters.rest_framework.DjangoFilterBackend",
"rest_framework.filters.OrderingFilter",
],
}

# These paths will work without authentication
Expand Down
1 change: 1 addition & 0 deletions backend/backend/urls_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,5 @@
UrlPathConstants.PROMPT_STUDIO,
include("prompt_studio.prompt_studio_index_manager_v2.urls"),
),
path("tags/", include("tags.urls")),
]
Loading
Loading