From a1aa325ce3266cd76f0e7860cd9b9355f9c5e084 Mon Sep 17 00:00:00 2001 From: jiangbo721 <365065261@qq.com> Date: Sat, 29 Mar 2025 14:15:53 +0800 Subject: [PATCH] Chore/code format and Repair commit_id 3254018d more deleted codes and Fix naming error ambiguity between workflow_run_id and workflow_id (#17075) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 刘江波 --- api/controllers/service_api/app/workflow.py | 6 +++--- api/core/app/task_pipeline/workflow_cycle_manage.py | 7 +++---- api/core/rag/index_processor/constant/built_in_field.py | 4 ++-- api/core/rag/index_processor/constant/index_type.py | 4 ++-- .../processor/parent_child_index_processor.py | 2 ++ api/models/model.py | 4 ++-- api/models/workflow.py | 4 ++-- .../entities/knowledge_entities/knowledge_entities.py | 4 ++-- .../components/develop/template/template_workflow.zh.mdx | 8 ++++---- 9 files changed, 22 insertions(+), 21 deletions(-) diff --git a/api/controllers/service_api/app/workflow.py b/api/controllers/service_api/app/workflow.py index 1cd7e5bf23..2854a43505 100644 --- a/api/controllers/service_api/app/workflow.py +++ b/api/controllers/service_api/app/workflow.py @@ -54,7 +54,7 @@ workflow_run_fields = { class WorkflowRunDetailApi(Resource): @validate_app_token @marshal_with(workflow_run_fields) - def get(self, app_model: App, workflow_id: str): + def get(self, app_model: App, workflow_run_id: str): """ Get a workflow task running detail """ @@ -62,7 +62,7 @@ class WorkflowRunDetailApi(Resource): if app_mode != AppMode.WORKFLOW: raise NotWorkflowAppError() - workflow_run = db.session.query(WorkflowRun).filter(WorkflowRun.id == workflow_id).first() + workflow_run = db.session.query(WorkflowRun).filter(WorkflowRun.id == workflow_run_id).first() return workflow_run @@ -163,6 +163,6 @@ class WorkflowAppLogApi(Resource): api.add_resource(WorkflowRunApi, "/workflows/run") -api.add_resource(WorkflowRunDetailApi, "/workflows/run/") +api.add_resource(WorkflowRunDetailApi, "/workflows/run/") api.add_resource(WorkflowTaskStopApi, "/workflows/tasks//stop") api.add_resource(WorkflowAppLogApi, "/workflows/logs") diff --git a/api/core/app/task_pipeline/workflow_cycle_manage.py b/api/core/app/task_pipeline/workflow_cycle_manage.py index 8204d0be85..ebae3285a6 100644 --- a/api/core/app/task_pipeline/workflow_cycle_manage.py +++ b/api/core/app/task_pipeline/workflow_cycle_manage.py @@ -44,6 +44,7 @@ from core.app.entities.task_entities import ( WorkflowFinishStreamResponse, WorkflowStartStreamResponse, ) +from core.app.task_pipeline.exc import WorkflowRunNotFoundError from core.file import FILE_MODEL_IDENTITY, File from core.model_runtime.utils.encoders import jsonable_encoder from core.ops.entities.trace_entity import TraceTaskName @@ -66,8 +67,6 @@ from models.workflow import ( WorkflowRunStatus, ) -from .exc import WorkflowRunNotFoundError - class WorkflowCycleManage: def __init__( @@ -166,7 +165,7 @@ class WorkflowCycleManage: outputs = WorkflowEntry.handle_special_values(outputs) - workflow_run.status = WorkflowRunStatus.SUCCEEDED.value + workflow_run.status = WorkflowRunStatus.SUCCEEDED workflow_run.outputs = json.dumps(outputs or {}) workflow_run.elapsed_time = time.perf_counter() - start_at workflow_run.total_tokens = total_tokens @@ -201,7 +200,7 @@ class WorkflowCycleManage: workflow_run = self._get_workflow_run(session=session, workflow_run_id=workflow_run_id) outputs = WorkflowEntry.handle_special_values(dict(outputs) if outputs else None) - workflow_run.status = WorkflowRunStatus.PARTIAL_SUCCESSED.value + workflow_run.status = WorkflowRunStatus.PARTIAL_SUCCEEDED.value workflow_run.outputs = json.dumps(outputs or {}) workflow_run.elapsed_time = time.perf_counter() - start_at workflow_run.total_tokens = total_tokens diff --git a/api/core/rag/index_processor/constant/built_in_field.py b/api/core/rag/index_processor/constant/built_in_field.py index 09c5e949eb..c8ad53e3dd 100644 --- a/api/core/rag/index_processor/constant/built_in_field.py +++ b/api/core/rag/index_processor/constant/built_in_field.py @@ -1,7 +1,7 @@ -from enum import Enum +from enum import Enum, StrEnum -class BuiltInField(str, Enum): +class BuiltInField(StrEnum): document_name = "document_name" uploader = "uploader" upload_date = "upload_date" diff --git a/api/core/rag/index_processor/constant/index_type.py b/api/core/rag/index_processor/constant/index_type.py index 0845b58e25..659086e808 100644 --- a/api/core/rag/index_processor/constant/index_type.py +++ b/api/core/rag/index_processor/constant/index_type.py @@ -1,7 +1,7 @@ -from enum import Enum +from enum import StrEnum -class IndexType(str, Enum): +class IndexType(StrEnum): PARAGRAPH_INDEX = "text_model" QA_INDEX = "qa_model" PARENT_CHILD_INDEX = "hierarchical_model" diff --git a/api/core/rag/index_processor/processor/parent_child_index_processor.py b/api/core/rag/index_processor/processor/parent_child_index_processor.py index 894b85339a..1cde5e1c8f 100644 --- a/api/core/rag/index_processor/processor/parent_child_index_processor.py +++ b/api/core/rag/index_processor/processor/parent_child_index_processor.py @@ -39,6 +39,8 @@ class ParentChildIndexProcessor(BaseIndexProcessor): all_documents = [] # type: ignore if rules.parent_mode == ParentMode.PARAGRAPH: # Split the text documents into nodes. + if not rules.segmentation: + raise ValueError("No segmentation found in rules.") splitter = self._get_splitter( processing_rule_mode=process_rule.get("mode"), max_tokens=rules.segmentation.max_tokens, diff --git a/api/models/model.py b/api/models/model.py index 05bc1fd301..8262109ba5 100644 --- a/api/models/model.py +++ b/api/models/model.py @@ -791,7 +791,7 @@ class Conversation(db.Model): # type: ignore[name-defined] WorkflowRunStatus.SUCCEEDED: 0, WorkflowRunStatus.FAILED: 0, WorkflowRunStatus.STOPPED: 0, - WorkflowRunStatus.PARTIAL_SUCCESSED: 0, + WorkflowRunStatus.PARTIAL_SUCCEEDED: 0, } for message in messages: @@ -802,7 +802,7 @@ class Conversation(db.Model): # type: ignore[name-defined] { "success": status_counts[WorkflowRunStatus.SUCCEEDED], "failed": status_counts[WorkflowRunStatus.FAILED], - "partial_success": status_counts[WorkflowRunStatus.PARTIAL_SUCCESSED], + "partial_success": status_counts[WorkflowRunStatus.PARTIAL_SUCCEEDED], } if messages else None diff --git a/api/models/workflow.py b/api/models/workflow.py index ed6820702c..cefb2a7de3 100644 --- a/api/models/workflow.py +++ b/api/models/workflow.py @@ -109,7 +109,7 @@ class Workflow(Base): tenant_id: Mapped[str] = mapped_column(StringUUID, nullable=False) app_id: Mapped[str] = mapped_column(StringUUID, nullable=False) type: Mapped[str] = mapped_column(db.String(255), nullable=False) - version: Mapped[str] + version: Mapped[str] = mapped_column(db.String(255), nullable=False) marked_name: Mapped[str] = mapped_column(default="", server_default="") marked_comment: Mapped[str] = mapped_column(default="", server_default="") graph: Mapped[str] = mapped_column(sa.Text) @@ -352,7 +352,7 @@ class WorkflowRunStatus(StrEnum): SUCCEEDED = "succeeded" FAILED = "failed" STOPPED = "stopped" - PARTIAL_SUCCESSED = "partial-succeeded" + PARTIAL_SUCCEEDED = "partial-succeeded" class WorkflowRun(Base): diff --git a/api/services/entities/knowledge_entities/knowledge_entities.py b/api/services/entities/knowledge_entities/knowledge_entities.py index 6aa7b51d44..bb3be61f85 100644 --- a/api/services/entities/knowledge_entities/knowledge_entities.py +++ b/api/services/entities/knowledge_entities/knowledge_entities.py @@ -1,4 +1,4 @@ -from enum import Enum +from enum import StrEnum from typing import Literal, Optional from pydantic import BaseModel @@ -11,7 +11,7 @@ class SegmentUpdateEntity(BaseModel): enabled: Optional[bool] = None -class ParentMode(str, Enum): +class ParentMode(StrEnum): FULL_DOC = "full-doc" PARAGRAPH = "paragraph" diff --git a/web/app/components/develop/template/template_workflow.zh.mdx b/web/app/components/develop/template/template_workflow.zh.mdx index 75ca3df925..939df2703d 100644 --- a/web/app/components/develop/template/template_workflow.zh.mdx +++ b/web/app/components/develop/template/template_workflow.zh.mdx @@ -318,7 +318,7 @@ Workflow 应用无会话支持,适合用于翻译/文章写作/总结 AI 等 --- 根据 workflow 执行 ID 获取 workflow 任务当前执行结果 ### Path - - `workflow_id` (string) workflow 执行 ID,可在流式返回 Chunk 中获取 + - `workflow_run_id` (string) workflow_run_id,可在流式返回 Chunk 中获取 ### Response - `id` (string) workflow 执行 ID - `workflow_id` (string) 关联的 Workflow ID @@ -343,9 +343,9 @@ Workflow 应用无会话支持,适合用于翻译/文章写作/总结 AI 等 ### Request Example - + ```bash {{ title: 'cURL' }} - curl -X GET '${props.appDetail.api_base_url}/workflows/run/:workflow_id' \ + curl -X GET '${props.appDetail.api_base_url}/workflows/run/:workflow_run_id' \ -H 'Authorization: Bearer {api_key}' \ -H 'Content-Type: application/json' ```