Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

feat(agent_node): ensure that the enum-checking syntax is compatible with Python 3.11. (#20373)

-LAN-f59fb94dae8c
diff --git a/api/core/workflow/nodes/agent/agent_node.py b/api/core/workflow/nodes/agent/agent_node.py
index 771e0ca7a51..9bed8862fcf 100644
--- a/api/core/workflow/nodes/agent/agent_node.py
+++ b/api/core/workflow/nodes/agent/agent_node.py
@@ -356,7 +356,9 @@ class AgentNode(ToolNode):
def _remove_unsupported_model_features_for_old_version(self, model_schema: AIModelEntity) -> AIModelEntity:
if model_schema.features:
- for feature in model_schema.features:
- if feature.value not in AgentOldVersionModelFeatures:
+ for feature in model_schema.features[:]: # Create a copy to safely modify during iteration
+ try:
+ AgentOldVersionModelFeatures(feature.value) # Try to create enum member from value
+ except ValueError:
model_schema.features.remove(feature)
return model_schema
diff --git a/api/core/workflow/nodes/agent/entities.py b/api/core/workflow/nodes/agent/entities.py
index 77e94375bff..075a41fb2f5 100644
--- a/api/core/workflow/nodes/agent/entities.py
+++ b/api/core/workflow/nodes/agent/entities.py
@@ -1,4 +1,4 @@
-from enum import Enum
+from enum import Enum, StrEnum
from typing import Any, Literal, Union
from pydantic import BaseModel
@@ -26,7 +26,7 @@ class ParamsAutoGenerated(Enum):
OPEN = 1
-class AgentOldVersionModelFeatures(Enum):
+class AgentOldVersionModelFeatures(StrEnum):
"""
Enum class for old SDK version llm feature.
"""
diff --git a/api/pyproject.toml b/api/pyproject.toml
index 1c6adb65878..50a765c0e10 100644
--- a/api/pyproject.toml
+++ b/api/pyproject.toml
@@ -149,6 +149,7 @@ dev = [
"types-tqdm~=4.67.0",
"types-ujson~=5.10.0",
"boto3-stubs>=1.38.20",
+ "types-jmespath>=1.0.2.20240106",
]
############################################################
diff --git a/api/uv.lock b/api/uv.lock
index 033dc8762b2..a1e1d6146ab 100644
--- a/api/uv.lock
+++ b/api/uv.lock
@@ -1315,6 +1315,7 @@ dev = [
{ name = "types-gevent" },
{ name = "types-greenlet" },
{ name = "types-html5lib" },
+ { name = "types-jmespath" },
{ name = "types-jsonschema" },
{ name = "types-markdown" },
{ name = "types-oauthlib" },
@@ -1486,6 +1487,7 @@ dev = [
{ name = "types-gevent", specifier = "~=24.11.0" },
{ name = "types-greenlet", specifier = "~=3.1.0" },
{ name = "types-html5lib", specifier = "~=1.1.11" },
+ { name = "types-jmespath", specifier = ">=1.0.2.20240106" },
{ name = "types-jsonschema", specifier = "~=4.23.0" },
{ name = "types-markdown", specifier = "~=3.7.0" },
{ name = "types-oauthlib", specifier = "~=3.2.0" },
@@ -5726,6 +5728,15 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/ba/7c/f862b1dc31268ef10fe95b43dcdf216ba21a592fafa2d124445cd6b92e93/types_html5lib-1.1.11.20241018-py3-none-any.whl", hash = "sha256:3f1e064d9ed2c289001ae6392c84c93833abb0816165c6ff0abfc304a779f403", size = 17292 },
]
+[[package]]
+name = "types-jmespath"
+version = "1.0.2.20240106"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/1b/e4/1f7414dbca03975f66f1ab1b3f7b3deb7c19b104ef14dd3c99036bbc39b2/types-jmespath-1.0.2.20240106.tar.gz", hash = "sha256:b4a65a116bfc1c700a4fd9d24e2e397f4a431122e0320a77b7f1989a6b5d819e", size = 5071 }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/f5/30/3d6443f782601dd88820ba31e7668abfec7e19d685ac7f6fbcfd6ebba519/types_jmespath-1.0.2.20240106-py3-none-any.whl", hash = "sha256:c3e715fcaae9e5f8d74e14328fdedc4f2b3f0e18df17f3e457ae0a18e245bde0", size = 6087 },
+]
+
[[package]]
name = "types-jsonschema"
version = "4.23.0.20241208"