From fc29f2003e294984d23afabb20da724520252f32 Mon Sep 17 00:00:00 2001 From: Warren Chen Date: Tue, 31 Dec 2024 00:36:03 +0800 Subject: [PATCH 1/4] translate comments (#12234) --- .../tools/provider/builtin/aws/tools/bedrock_retrieve.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api/core/tools/provider/builtin/aws/tools/bedrock_retrieve.yaml b/api/core/tools/provider/builtin/aws/tools/bedrock_retrieve.yaml index d4c5c5f64a748d..31961a0cf03024 100644 --- a/api/core/tools/provider/builtin/aws/tools/bedrock_retrieve.yaml +++ b/api/core/tools/provider/builtin/aws/tools/bedrock_retrieve.yaml @@ -73,9 +73,9 @@ parameters: llm_description: AWS region where the Bedrock Knowledge Base is located form: form - - name: metadata_filter # 新增的元数据过滤参数 - type: string # 可以是字符串类型,包含 JSON 格式的过滤条件 - required: false # 可选参数 + - name: metadata_filter # Additional parameter for metadata filtering + type: string # String type, expects JSON-formatted filter conditions + required: false # Optional field - can be omitted label: en_US: Metadata Filter zh_Hans: 元数据过滤器 From d4b848272e5f60d041432334e01e487d7939de8b Mon Sep 17 00:00:00 2001 From: -LAN- Date: Tue, 31 Dec 2024 11:42:51 +0800 Subject: [PATCH 2/4] fix: apply gevent threading patch early and ensure unique workflow node execution IDs (#12196) Signed-off-by: -LAN- --- api/app.py | 22 +++++++++++-------- .../task_pipeline/workflow_cycle_manage.py | 6 ++--- api/libs/threadings_utils.py | 19 ---------------- api/libs/version_utils.py | 12 ---------- 4 files changed, 16 insertions(+), 43 deletions(-) delete mode 100644 api/libs/threadings_utils.py delete mode 100644 api/libs/version_utils.py diff --git a/api/app.py b/api/app.py index c6a08290804a65..e6649e59df70b5 100644 --- a/api/app.py +++ b/api/app.py @@ -1,12 +1,8 @@ -from libs import version_utils - -# preparation before creating app -version_utils.check_supported_python_version() +import os +import sys def is_db_command(): - import sys - if len(sys.argv) > 1 and sys.argv[0].endswith("flask") and sys.argv[1] == "db": return True return False @@ -18,10 +14,18 @@ def is_db_command(): app = create_migrations_app() else: - from app_factory import create_app - from libs import threadings_utils + if os.environ.get("FLASK_DEBUG", "False") != "True": + from gevent import monkey # type: ignore + + # gevent + monkey.patch_all() - threadings_utils.apply_gevent_threading_patch() + from grpc.experimental import gevent as grpc_gevent # type: ignore + + # grpc gevent + grpc_gevent.init_gevent() + + from app_factory import create_app app = create_app() celery = app.extensions["celery"] diff --git a/api/core/app/task_pipeline/workflow_cycle_manage.py b/api/core/app/task_pipeline/workflow_cycle_manage.py index 7215105a5652da..e21475271a03d7 100644 --- a/api/core/app/task_pipeline/workflow_cycle_manage.py +++ b/api/core/app/task_pipeline/workflow_cycle_manage.py @@ -274,7 +274,7 @@ def _handle_node_execution_start( self, *, session: Session, workflow_run: WorkflowRun, event: QueueNodeStartedEvent ) -> WorkflowNodeExecution: workflow_node_execution = WorkflowNodeExecution() - workflow_node_execution.id = event.node_execution_id + workflow_node_execution.id = str(uuid4()) workflow_node_execution.tenant_id = workflow_run.tenant_id workflow_node_execution.app_id = workflow_run.app_id workflow_node_execution.workflow_id = workflow_run.workflow_id @@ -391,7 +391,7 @@ def _handle_workflow_node_execution_retried( execution_metadata = json.dumps(merged_metadata) workflow_node_execution = WorkflowNodeExecution() - workflow_node_execution.id = event.node_execution_id + workflow_node_execution.id = str(uuid4()) workflow_node_execution.tenant_id = workflow_run.tenant_id workflow_node_execution.app_id = workflow_run.app_id workflow_node_execution.workflow_id = workflow_run.workflow_id @@ -824,7 +824,7 @@ def _get_workflow_run(self, *, session: Session, workflow_run_id: str) -> Workfl return workflow_run def _get_workflow_node_execution(self, session: Session, node_execution_id: str) -> WorkflowNodeExecution: - stmt = select(WorkflowNodeExecution).where(WorkflowNodeExecution.id == node_execution_id) + stmt = select(WorkflowNodeExecution).where(WorkflowNodeExecution.node_execution_id == node_execution_id) workflow_node_execution = session.scalar(stmt) if not workflow_node_execution: raise WorkflowNodeExecutionNotFoundError(node_execution_id) diff --git a/api/libs/threadings_utils.py b/api/libs/threadings_utils.py deleted file mode 100644 index e4d63fd3142ce2..00000000000000 --- a/api/libs/threadings_utils.py +++ /dev/null @@ -1,19 +0,0 @@ -from configs import dify_config - - -def apply_gevent_threading_patch(): - """ - Run threading patch by gevent - to make standard library threading compatible. - Patching should be done as early as possible in the lifecycle of the program. - :return: - """ - if not dify_config.DEBUG: - from gevent import monkey # type: ignore - from grpc.experimental import gevent as grpc_gevent # type: ignore - - # gevent - monkey.patch_all() - - # grpc gevent - grpc_gevent.init_gevent() diff --git a/api/libs/version_utils.py b/api/libs/version_utils.py deleted file mode 100644 index 10edf8a058abf7..00000000000000 --- a/api/libs/version_utils.py +++ /dev/null @@ -1,12 +0,0 @@ -import sys - - -def check_supported_python_version(): - python_version = sys.version_info - if not ((3, 11) <= python_version < (3, 13)): - print( - "Aborted to launch the service " - f" with unsupported Python version {python_version.major}.{python_version.minor}." - " Please ensure Python 3.11 or 3.12." - ) - raise SystemExit(1) From fbf5deda2152286d085c080f748ac5c2aa83e99e Mon Sep 17 00:00:00 2001 From: Han K Date: Tue, 31 Dec 2024 13:46:51 +0800 Subject: [PATCH 3/4] =?UTF-8?q?fix(env):=20docker=20compose=20variable=20i?= =?UTF-8?q?nterpolation=20issue=20for=20COMPOSE=5FPRO=E2=80=A6=20(#12093)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Han Kyaw --- docker/docker-compose.yaml | 1 - docker/generate_docker_compose | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml index 2697e3eb605ffe..b82659d959f178 100644 --- a/docker/docker-compose.yaml +++ b/docker/docker-compose.yaml @@ -374,7 +374,6 @@ x-shared-env: &shared-api-worker-env SSRF_COREDUMP_DIR: ${SSRF_COREDUMP_DIR:-/var/spool/squid} SSRF_REVERSE_PROXY_PORT: ${SSRF_REVERSE_PROXY_PORT:-8194} SSRF_SANDBOX_HOST: ${SSRF_SANDBOX_HOST:-sandbox} - COMPOSE_PROFILES: ${COMPOSE_PROFILES:-${VECTOR_STORE:-weaviate}} EXPOSE_NGINX_PORT: ${EXPOSE_NGINX_PORT:-80} EXPOSE_NGINX_SSL_PORT: ${EXPOSE_NGINX_SSL_PORT:-443} POSITION_TOOL_PINS: ${POSITION_TOOL_PINS:-} diff --git a/docker/generate_docker_compose b/docker/generate_docker_compose index dc4460f96cf9be..b5c0acefb123dd 100755 --- a/docker/generate_docker_compose +++ b/docker/generate_docker_compose @@ -37,6 +37,8 @@ def generate_shared_env_block(env_vars, anchor_name="shared-api-worker-env"): """ lines = [f"x-shared-env: &{anchor_name}"] for key, default in env_vars.items(): + if key == "COMPOSE_PROFILES": + continue # If default value is empty, use ${KEY:-} if default == "": lines.append(f" {key}: ${{{key}:-}}") From 634b382a3d14e27a17e727d5a0311c8a87caafdc Mon Sep 17 00:00:00 2001 From: -LAN- Date: Tue, 31 Dec 2024 14:01:24 +0800 Subject: [PATCH 4/4] fix: enhance ToolEngineInvokeError to include meta information (#12238) Signed-off-by: -LAN- --- api/core/tools/errors.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/api/core/tools/errors.py b/api/core/tools/errors.py index 6febf137b000f9..c5f9ca477401f2 100644 --- a/api/core/tools/errors.py +++ b/api/core/tools/errors.py @@ -31,3 +31,7 @@ class ToolApiSchemaError(ValueError): class ToolEngineInvokeError(Exception): meta: ToolInvokeMeta + + def __init__(self, meta, **kwargs): + self.meta = meta + super().__init__(**kwargs)