chore: refurish python code by applying Pylint linter rules (#8322)
This commit is contained in:
@@ -148,11 +148,11 @@ class AnswerStreamGeneratorRouter:
|
||||
for edge in reverse_edges:
|
||||
source_node_id = edge.source_node_id
|
||||
source_node_type = node_id_config_mapping[source_node_id].get("data", {}).get("type")
|
||||
if source_node_type in (
|
||||
if source_node_type in {
|
||||
NodeType.ANSWER.value,
|
||||
NodeType.IF_ELSE.value,
|
||||
NodeType.QUESTION_CLASSIFIER.value,
|
||||
):
|
||||
}:
|
||||
answer_dependencies[answer_node_id].append(source_node_id)
|
||||
else:
|
||||
cls._recursive_fetch_answer_dependencies(
|
||||
|
@@ -136,10 +136,10 @@ class EndStreamGeneratorRouter:
|
||||
for edge in reverse_edges:
|
||||
source_node_id = edge.source_node_id
|
||||
source_node_type = node_id_config_mapping[source_node_id].get("data", {}).get("type")
|
||||
if source_node_type in (
|
||||
if source_node_type in {
|
||||
NodeType.IF_ELSE.value,
|
||||
NodeType.QUESTION_CLASSIFIER,
|
||||
):
|
||||
}:
|
||||
end_dependencies[end_node_id].append(source_node_id)
|
||||
else:
|
||||
cls._recursive_fetch_end_dependencies(
|
||||
|
@@ -6,8 +6,8 @@ from urllib.parse import urlencode
|
||||
|
||||
import httpx
|
||||
|
||||
import core.helper.ssrf_proxy as ssrf_proxy
|
||||
from configs import dify_config
|
||||
from core.helper import ssrf_proxy
|
||||
from core.workflow.entities.variable_entities import VariableSelector
|
||||
from core.workflow.entities.variable_pool import VariablePool
|
||||
from core.workflow.nodes.http_request.entities import (
|
||||
@@ -176,7 +176,7 @@ class HttpExecutor:
|
||||
elif node_data.body.type == "x-www-form-urlencoded" and not content_type_is_set:
|
||||
self.headers["Content-Type"] = "application/x-www-form-urlencoded"
|
||||
|
||||
if node_data.body.type in ["form-data", "x-www-form-urlencoded"]:
|
||||
if node_data.body.type in {"form-data", "x-www-form-urlencoded"}:
|
||||
body = self._to_dict(body_data)
|
||||
|
||||
if node_data.body.type == "form-data":
|
||||
@@ -187,7 +187,7 @@ class HttpExecutor:
|
||||
self.headers["Content-Type"] = f"multipart/form-data; boundary={self.boundary}"
|
||||
else:
|
||||
self.body = urlencode(body)
|
||||
elif node_data.body.type in ["json", "raw-text"]:
|
||||
elif node_data.body.type in {"json", "raw-text"}:
|
||||
self.body = body_data
|
||||
elif node_data.body.type == "none":
|
||||
self.body = ""
|
||||
@@ -258,7 +258,7 @@ class HttpExecutor:
|
||||
"follow_redirects": True,
|
||||
}
|
||||
|
||||
if self.method in ("get", "head", "post", "put", "delete", "patch"):
|
||||
if self.method in {"get", "head", "post", "put", "delete", "patch"}:
|
||||
response = getattr(ssrf_proxy, self.method)(data=self.body, files=self.files, **kwargs)
|
||||
else:
|
||||
raise ValueError(f"Invalid http method {self.method}")
|
||||
|
@@ -33,7 +33,7 @@ class ParameterConfig(BaseModel):
|
||||
def validate_name(cls, value) -> str:
|
||||
if not value:
|
||||
raise ValueError("Parameter name is required")
|
||||
if value in ["__reason", "__is_success"]:
|
||||
if value in {"__reason", "__is_success"}:
|
||||
raise ValueError("Invalid parameter name, __reason and __is_success are reserved")
|
||||
return value
|
||||
|
||||
@@ -66,7 +66,7 @@ class ParameterExtractorNodeData(BaseNodeData):
|
||||
for parameter in self.parameters:
|
||||
parameter_schema = {"description": parameter.description}
|
||||
|
||||
if parameter.type in ["string", "select"]:
|
||||
if parameter.type in {"string", "select"}:
|
||||
parameter_schema["type"] = "string"
|
||||
elif parameter.type.startswith("array"):
|
||||
parameter_schema["type"] = "array"
|
||||
|
@@ -467,7 +467,7 @@ class ParameterExtractorNode(LLMNode):
|
||||
# transformed_result[parameter.name] = bool(result[parameter.name].lower() == 'true')
|
||||
# elif isinstance(result[parameter.name], int):
|
||||
# transformed_result[parameter.name] = bool(result[parameter.name])
|
||||
elif parameter.type in ["string", "select"]:
|
||||
elif parameter.type in {"string", "select"}:
|
||||
if isinstance(result[parameter.name], str):
|
||||
transformed_result[parameter.name] = result[parameter.name]
|
||||
elif parameter.type.startswith("array"):
|
||||
@@ -498,7 +498,7 @@ class ParameterExtractorNode(LLMNode):
|
||||
transformed_result[parameter.name] = 0
|
||||
elif parameter.type == "bool":
|
||||
transformed_result[parameter.name] = False
|
||||
elif parameter.type in ["string", "select"]:
|
||||
elif parameter.type in {"string", "select"}:
|
||||
transformed_result[parameter.name] = ""
|
||||
elif parameter.type.startswith("array"):
|
||||
transformed_result[parameter.name] = []
|
||||
@@ -516,9 +516,9 @@ class ParameterExtractorNode(LLMNode):
|
||||
"""
|
||||
stack = []
|
||||
for i, c in enumerate(text):
|
||||
if c == "{" or c == "[":
|
||||
if c in {"{", "["}:
|
||||
stack.append(c)
|
||||
elif c == "}" or c == "]":
|
||||
elif c in {"}", "]"}:
|
||||
# check if stack is empty
|
||||
if not stack:
|
||||
return text[:i]
|
||||
@@ -560,7 +560,7 @@ class ParameterExtractorNode(LLMNode):
|
||||
result[parameter.name] = 0
|
||||
elif parameter.type == "bool":
|
||||
result[parameter.name] = False
|
||||
elif parameter.type in ["string", "select"]:
|
||||
elif parameter.type in {"string", "select"}:
|
||||
result[parameter.name] = ""
|
||||
|
||||
return result
|
||||
|
@@ -163,10 +163,7 @@ class ToolNode(BaseNode):
|
||||
result = []
|
||||
|
||||
for response in tool_response:
|
||||
if (
|
||||
response.type == ToolInvokeMessage.MessageType.IMAGE_LINK
|
||||
or response.type == ToolInvokeMessage.MessageType.IMAGE
|
||||
):
|
||||
if response.type in {ToolInvokeMessage.MessageType.IMAGE_LINK, ToolInvokeMessage.MessageType.IMAGE}:
|
||||
url = response.message
|
||||
ext = path.splitext(url)[1]
|
||||
mimetype = response.meta.get("mime_type", "image/jpeg")
|
||||
|
Reference in New Issue
Block a user