feat: evaluation (#35290)

Co-authored-by: jyong <718720800@qq.com>
Co-authored-by: Yansong Zhang <916125788@qq.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: hj24 <mambahj24@gmail.com>
Co-authored-by: hj24 <huangjian@dify.ai>
Co-authored-by: Joel <iamjoel007@gmail.com>
Co-authored-by: Stephen Zhou <38493346+hyoban@users.noreply.github.com>
Co-authored-by: CodingOnStar <hanxujiang@dify.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
This commit is contained in:
FFXN
2026-04-16 11:25:23 +08:00
committed by GitHub
parent f9b76f0f52
commit 5e7d9eff84

View File

@ -4,7 +4,7 @@ from functools import wraps
from typing import ParamSpec, TypeVar
from flask import request
from flask_restx import Resource, marshal_with
from flask_restx import Resource, fields, marshal_with
from sqlalchemy.orm import Session
from werkzeug.exceptions import InternalServerError, NotFound
@ -63,6 +63,11 @@ register_schema_models(
)
snippet_workflow_model = console_ns.clone("SnippetWorkflow", workflow_model, {
"input_fields": fields.Raw(default=[]),
})
class SnippetNotFoundError(Exception):
"""Snippet not found error."""
@ -100,14 +105,14 @@ def get_snippet(view_func: Callable[P, R]):
@console_ns.route("/snippets/<uuid:snippet_id>/workflows/draft")
class SnippetDraftWorkflowApi(Resource):
@console_ns.doc("get_snippet_draft_workflow")
@console_ns.response(200, "Draft workflow retrieved successfully", workflow_model)
@console_ns.response(200, "Draft workflow retrieved successfully", snippet_workflow_model)
@console_ns.response(404, "Snippet or draft workflow not found")
@setup_required
@login_required
@account_initialization_required
@get_snippet
@edit_permission_required
@marshal_with(workflow_model)
@marshal_with(snippet_workflow_model)
def get(self, snippet: CustomizedSnippet):
"""Get draft workflow for snippet."""
snippet_service = SnippetService()
@ -118,6 +123,7 @@ class SnippetDraftWorkflowApi(Resource):
db.session.expunge(workflow)
workflow.conversation_variables = []
workflow.input_fields = snippet.input_fields_list
return workflow
@console_ns.doc("sync_snippet_draft_workflow")
@ -175,14 +181,14 @@ class SnippetDraftConfigApi(Resource):
@console_ns.route("/snippets/<uuid:snippet_id>/workflows/publish")
class SnippetPublishedWorkflowApi(Resource):
@console_ns.doc("get_snippet_published_workflow")
@console_ns.response(200, "Published workflow retrieved successfully", workflow_model)
@console_ns.response(200, "Published workflow retrieved successfully", snippet_workflow_model)
@console_ns.response(404, "Snippet not found")
@setup_required
@login_required
@account_initialization_required
@get_snippet
@edit_permission_required
@marshal_with(workflow_model)
@marshal_with(snippet_workflow_model)
def get(self, snippet: CustomizedSnippet):
"""Get published workflow for snippet."""
if not snippet.is_published:
@ -191,6 +197,9 @@ class SnippetPublishedWorkflowApi(Resource):
snippet_service = SnippetService()
workflow = snippet_service.get_published_workflow(snippet=snippet)
if workflow:
workflow.input_fields = snippet.input_fields_list
return workflow
@console_ns.doc("publish_snippet_workflow")