From ae1f3780f86ba5e74c46435d2a78ff2e1f77d78e Mon Sep 17 00:00:00 2001 From: Yeuoly <45712896+Yeuoly@users.noreply.github.com> Date: Fri, 12 Apr 2024 17:46:39 +0800 Subject: [PATCH] Feat/api tool custom timeout (#3420) --- api/.env.example | 4 ++++ api/core/tools/tool/api_tool.py | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/api/.env.example b/api/.env.example index bbcb7cf1ec..b99864a946 100644 --- a/api/.env.example +++ b/api/.env.example @@ -149,3 +149,7 @@ TEMPLATE_TRANSFORM_MAX_LENGTH=80000 CODE_MAX_STRING_ARRAY_LENGTH=30 CODE_MAX_OBJECT_ARRAY_LENGTH=30 CODE_MAX_NUMBER_ARRAY_LENGTH=1000 + +# API Tool configuration +API_TOOL_DEFAULT_CONNECT_TIMEOUT=10 +API_TOOL_DEFAULT_READ_TIMEOUT=60 diff --git a/api/core/tools/tool/api_tool.py b/api/core/tools/tool/api_tool.py index de3cd552d4..4037ef627c 100644 --- a/api/core/tools/tool/api_tool.py +++ b/api/core/tools/tool/api_tool.py @@ -1,5 +1,6 @@ import json from json import dumps +from os import getenv from typing import Any, Union from urllib.parse import urlencode @@ -13,7 +14,10 @@ from core.tools.entities.user_entities import UserToolProvider from core.tools.errors import ToolInvokeError, ToolParameterValidationError, ToolProviderCredentialValidationError from core.tools.tool.tool import Tool -API_TOOL_DEFAULT_TIMEOUT = (10, 60) +API_TOOL_DEFAULT_TIMEOUT = ( + int(getenv('API_TOOL_DEFAULT_CONNECT_TIMEOUT', '10')), + int(getenv('API_TOOL_DEFAULT_READ_TIMEOUT', '60')) +) class ApiTool(Tool): api_bundle: ApiBasedToolBundle