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.

example of remove some reflections (#24488)

Asuka Minato99fec40117cb
diff --git a/api/core/tools/custom_tool/tool.py b/api/core/tools/custom_tool/tool.py
index 3c0bfa52408..97342640f5c 100644
--- a/api/core/tools/custom_tool/tool.py
+++ b/api/core/tools/custom_tool/tool.py
@@ -275,35 +275,30 @@ class ApiTool(Tool):
if files:
headers.pop("Content-Type", None)
- if method in {
- "get",
- "head",
- "post",
- "put",
- "delete",
- "patch",
- "options",
- "GET",
- "POST",
- "PUT",
- "PATCH",
- "DELETE",
- "HEAD",
- "OPTIONS",
- }:
- response: httpx.Response = getattr(ssrf_proxy, method.lower())(
- url,
- params=params,
- headers=headers,
- cookies=cookies,
- data=body,
- files=files,
- timeout=API_TOOL_DEFAULT_TIMEOUT,
- follow_redirects=True,
- )
- return response
- else:
+ _METHOD_MAP = {
+ "get": ssrf_proxy.get,
+ "head": ssrf_proxy.head,
+ "post": ssrf_proxy.post,
+ "put": ssrf_proxy.put,
+ "delete": ssrf_proxy.delete,
+ "patch": ssrf_proxy.patch,
+ }
+ method_lc = method.lower()
+ if method_lc not in _METHOD_MAP:
raise ValueError(f"Invalid http method {method}")
+ response: httpx.Response = _METHOD_MAP[
+ method_lc
+ ]( # https://discuss.python.org/t/type-inference-for-function-return-types/42926
+ url,
+ params=params,
+ headers=headers,
+ cookies=cookies,
+ data=body,
+ files=files,
+ timeout=API_TOOL_DEFAULT_TIMEOUT,
+ follow_redirects=True,
+ )
+ return response
def _convert_body_property_any_of(
self, property: dict[str, Any], value: Any, any_of: list[dict[str, Any]], max_recursive=10