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.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
feat(*): Swtich to dify_config. (#6025)
-LAN-4d105d7bd7e1
diff --git a/api/configs/app_config.py b/api/configs/app_config.pyindex e5edc86bc3d..38921affd93 100644--- a/api/configs/app_config.py+++ b/api/configs/app_config.py@@ -1,3 +1,4 @@+from pydantic import computed_fieldfrom pydantic_settings import BaseSettings, SettingsConfigDictfrom configs.deploy import DeploymentConfig@@ -43,3 +44,28 @@ class DifyConfig(# ignore extra attributesextra='ignore',)++ CODE_MAX_NUMBER: int = 9223372036854775807+ CODE_MIN_NUMBER: int = -9223372036854775808+ CODE_MAX_STRING_LENGTH: int = 80000+ CODE_MAX_STRING_ARRAY_LENGTH: int = 30+ CODE_MAX_OBJECT_ARRAY_LENGTH: int = 30+ CODE_MAX_NUMBER_ARRAY_LENGTH: int = 1000++ HTTP_REQUEST_MAX_CONNECT_TIMEOUT: int = 300+ HTTP_REQUEST_MAX_READ_TIMEOUT: int = 600+ HTTP_REQUEST_MAX_WRITE_TIMEOUT: int = 600+ HTTP_REQUEST_NODE_MAX_BINARY_SIZE: int = 1024 * 1024 * 10++ @computed_field+ def HTTP_REQUEST_NODE_READABLE_MAX_BINARY_SIZE(self) -> str:+ return f'{self.HTTP_REQUEST_NODE_MAX_BINARY_SIZE / 1024 / 1024:.2f}MB'++ HTTP_REQUEST_NODE_MAX_TEXT_SIZE: int = 1024 * 1024++ @computed_field+ def HTTP_REQUEST_NODE_READABLE_MAX_TEXT_SIZE(self) -> str:+ return f'{self.HTTP_REQUEST_NODE_MAX_TEXT_SIZE / 1024 / 1024:.2f}MB'++ SSRF_PROXY_HTTP_URL: str | None = None+ SSRF_PROXY_HTTPS_URL: str | None = None\ No newline at end of filediff --git a/api/controllers/console/auth/data_source_oauth.py b/api/controllers/console/auth/data_source_oauth.pyindex 293ec1c4d34..62683472448 100644--- a/api/controllers/console/auth/data_source_oauth.py+++ b/api/controllers/console/auth/data_source_oauth.py@@ -6,6 +6,7 @@ from flask_login import current_userfrom flask_restful import Resourcefrom werkzeug.exceptions import Forbidden+from configs import dify_configfrom controllers.console import apifrom libs.login import login_requiredfrom libs.oauth_data_source import NotionOAuth@@ -16,11 +17,11 @@ from ..wraps import account_initialization_requireddef get_oauth_providers():with current_app.app_context():- notion_oauth = NotionOAuth(client_id=current_app.config.get('NOTION_CLIENT_ID'),- client_secret=current_app.config.get(- 'NOTION_CLIENT_SECRET'),- redirect_uri=current_app.config.get(- 'CONSOLE_API_URL') + '/console/api/oauth/data-source/callback/notion')+ if not dify_config.NOTION_CLIENT_ID or not dify_config.NOTION_CLIENT_SECRET:+ return {}+ notion_oauth = NotionOAuth(client_id=dify_config.NOTION_CLIENT_ID,+ client_secret=dify_config.NOTION_CLIENT_SECRET,+ redirect_uri=dify_config.CONSOLE_API_URL + '/console/api/oauth/data-source/callback/notion')OAUTH_PROVIDERS = {'notion': notion_oauth@@ -39,8 +40,10 @@ class OAuthDataSource(Resource):print(vars(oauth_provider))if not oauth_provider:return {'error': 'Invalid provider'}, 400- if current_app.config.get('NOTION_INTEGRATION_TYPE') == 'internal':- internal_secret = current_app.config.get('NOTION_INTERNAL_SECRET')+ if dify_config.NOTION_INTEGRATION_TYPE == 'internal':+ internal_secret = dify_config.NOTION_INTERNAL_SECRET+ if not internal_secret:+ return {'error': 'Internal secret is not set'},oauth_provider.save_internal_access_token(internal_secret)return { 'data': '' }else:@@ -60,13 +63,13 @@ class OAuthDataSourceCallback(Resource):if 'code' in request.args:code = request.args.get('code')- return redirect(f'{current_app.config.get("CONSOLE_WEB_URL")}?type=notion&code={code}')+ return redirect(f'{dify_config.CONSOLE_WEB_URL}?type=notion&code={code}')elif 'error' in request.args:error = request.args.get('error')- return redirect(f'{current_app.config.get("CONSOLE_WEB_URL")}?type=notion&error={error}')+ return redirect(f'{dify_config.CONSOLE_WEB_URL}?type=notion&error={error}')else:- return redirect(f'{current_app.config.get("CONSOLE_WEB_URL")}?type=notion&error=Access denied')+ return redirect(f'{dify_config.CONSOLE_WEB_URL}?type=notion&error=Access denied')class OAuthDataSourceBinding(Resource):diff --git a/api/controllers/console/auth/login.py b/api/controllers/console/auth/login.pyindex 67d6dc8e95f..3a0e5ea94dc 100644--- a/api/controllers/console/auth/login.py+++ b/api/controllers/console/auth/login.py@@ -1,7 +1,7 @@from typing import castimport flask_login-from flask import current_app, request+from flask import requestfrom flask_restful import Resource, reqparseimport services@@ -56,14 +56,14 @@ class LogoutApi(Resource):class ResetPasswordApi(Resource):@setup_requireddef get(self):- parser = reqparse.RequestParser()- parser.add_argument('email', type=email, required=True, location='json')- args = parser.parse_args()+ # parser = reqparse.RequestParser()+ # parser.add_argument('email', type=email, required=True, location='json')+ # args = parser.parse_args()# import mailchimp_transactional as MailchimpTransactional# from mailchimp_transactional.api_client import ApiClientError- account = {'email': args['email']}+ # account = {'email': args['email']}# account = AccountService.get_by_email(args['email'])# if account is None:# raise ValueError('Email not found')@@ -71,22 +71,22 @@ class ResetPasswordApi(Resource):# AccountService.update_password(account, new_password)# todo: Send email- MAILCHIMP_API_KEY = current_app.config['MAILCHIMP_TRANSACTIONAL_API_KEY']+ # MAILCHIMP_API_KEY = current_app.config['MAILCHIMP_TRANSACTIONAL_API_KEY']# mailchimp = MailchimpTransactional(MAILCHIMP_API_KEY)- message = {- 'from_email': '[email protected]',- 'to': [{'email': account.email}],- 'subject': 'Reset your Dify password',- 'html': """- <p>Dear User,</p>- <p>The Dify team has generated a new password for you, details as follows:</p>- <p><strong>{new_password}</strong></p>- <p>Please change your password to log in as soon as possible.</p>- <p>Regards,</p>- <p>The Dify Team</p>- """- }+ # message = {+ # 'from_email': '[email protected]',+ # 'to': [{'email': account['email']}],+ # 'subject': 'Reset your Dify password',+ # 'html': """+ # <p>Dear User,</p>+ # <p>The Dify team has generated a new password for you, details as follows:</p>+ # <p><strong>{new_password}</strong></p>+ # <p>Please change your password to log in as soon as possible.</p>+ # <p>Regards,</p>+ # <p>The Dify Team</p>+ # """+ # }# response = mailchimp.messages.send({# 'message': message,diff --git a/api/controllers/console/auth/oauth.py b/api/controllers/console/auth/oauth.pyindex 2e4a627e066..4a651bfe7b0 100644--- a/api/controllers/console/auth/oauth.py+++ b/api/controllers/console/auth/oauth.py@@ -6,6 +6,7 @@ import requestsfrom flask import current_app, redirect, requestfrom flask_restful import Resource+from configs import dify_configfrom constants.languages import languagesfrom extensions.ext_database import dbfrom libs.helper import get_remote_ip@@ -18,22 +19,24 @@ from .. import apidef get_oauth_providers():with current_app.app_context():- github_oauth = GitHubOAuth(client_id=current_app.config.get('GITHUB_CLIENT_ID'),- client_secret=current_app.config.get(- 'GITHUB_CLIENT_SECRET'),- redirect_uri=current_app.config.get(- 'CONSOLE_API_URL') + '/console/api/oauth/authorize/github')-- google_oauth = GoogleOAuth(client_id=current_app.config.get('GOOGLE_CLIENT_ID'),- client_secret=current_app.config.get(- 'GOOGLE_CLIENT_SECRET'),- redirect_uri=current_app.config.get(- 'CONSOLE_API_URL') + '/console/api/oauth/authorize/google')-- OAUTH_PROVIDERS = {- 'github': github_oauth,- 'google': google_oauth- }+ if not dify_config.GITHUB_CLIENT_ID or not dify_config.GITHUB_CLIENT_SECRET:+ github_oauth = None+ else:+ github_oauth = GitHubOAuth(+ client_id=dify_config.GITHUB_CLIENT_ID,+ client_secret=dify_config.GITHUB_CLIENT_SECRET,+ redirect_uri=dify_config.CONSOLE_API_URL + '/console/api/oauth/authorize/github',+ )+ if not dify_config.GOOGLE_CLIENT_ID or not dify_config.GOOGLE_CLIENT_SECRET:+ google_oauth = None+ else:+ google_oauth = GoogleOAuth(+ client_id=dify_config.GOOGLE_CLIENT_ID,+ client_secret=dify_config.GOOGLE_CLIENT_SECRET,+ redirect_uri=dify_config.CONSOLE_API_URL + '/console/api/oauth/authorize/google',+ )++ OAUTH_PROVIDERS = {'github': github_oauth, 'google': google_oauth}return OAUTH_PROVIDERS@@ -63,8 +66,7 @@ class OAuthCallback(Resource):token = oauth_provider.get_access_token(code)user_info = oauth_provider.get_user_info(token)except requests.exceptions.HTTPError as e:- logging.exception(- f"An error occurred during the OAuth process with {provider}: {e.response.text}")+ logging.exception(f'An error occurred during the OAuth process with {provider}: {e.response.text}')return {'error': 'OAuth process failed'}, 400account = _generate_account(provider, user_info)@@ -81,7 +83,7 @@ class OAuthCallback(Resource):token = AccountService.login(account, ip_address=get_remote_ip(request))- return redirect(f'{current_app.config.get("CONSOLE_WEB_URL")}?console_token={token}')+ return redirect(f'{dify_config.CONSOLE_WEB_URL}?console_token={token}')def _get_account_by_openid_or_email(provider: str, user_info: OAuthUserInfo) -> Optional[Account]:@@ -101,11 +103,7 @@ def _generate_account(provider: str, user_info: OAuthUserInfo):# Create accountaccount_name = user_info.name if user_info.name else 'Dify'account = RegisterService.register(- email=user_info.email,- name=account_name,- password=None,- open_id=user_info.id,- provider=provider+ email=user_info.email, name=account_name, password=None, open_id=user_info.id, provider=provider)# Set interface languagediff --git a/api/core/extension/api_based_extension_requestor.py b/api/core/extension/api_based_extension_requestor.pyindex 40e60687b2b..4db7a999736 100644--- a/api/core/extension/api_based_extension_requestor.py+++ b/api/core/extension/api_based_extension_requestor.py@@ -1,7 +1,6 @@-import os-import requests+from configs import dify_configfrom models.api_based_extension import APIBasedExtensionPoint@@ -31,10 +30,10 @@ class APIBasedExtensionRequestor:try:# proxy support for securityproxies = None- if os.environ.get("SSRF_PROXY_HTTP_URL") and os.environ.get("SSRF_PROXY_HTTPS_URL"):+ if dify_config.SSRF_PROXY_HTTP_URL and dify_config.SSRF_PROXY_HTTPS_URL:proxies = {- 'http': os.environ.get("SSRF_PROXY_HTTP_URL"),- 'https': os.environ.get("SSRF_PROXY_HTTPS_URL"),+ 'http': dify_config.SSRF_PROXY_HTTP_URL,+ 'https': dify_config.SSRF_PROXY_HTTPS_URL,}response = requests.request(diff --git a/api/core/helper/code_executor/code_executor.py b/api/core/helper/code_executor/code_executor.pyindex ec731693b6a..f094f7d79b5 100644--- a/api/core/helper/code_executor/code_executor.py+++ b/api/core/helper/code_executor/code_executor.py@@ -1,5 +1,4 @@import logging-import osimport timefrom enum import Enumfrom threading import Lock@@ -9,6 +8,7 @@ from httpx import get, postfrom pydantic import BaseModelfrom yarl import URL+from configs import dify_configfrom core.helper.code_executor.entities import CodeDependencyfrom core.helper.code_executor.javascript.javascript_transformer import NodeJsTemplateTransformerfrom core.helper.code_executor.jinja2.jinja2_transformer import Jinja2TemplateTransformer@@ -18,8 +18,8 @@ from core.helper.code_executor.template_transformer import TemplateTransformerlogger = logging.getLogger(__name__)# Code Executor-CODE_EXECUTION_ENDPOINT = os.environ.get('CODE_EXECUTION_ENDPOINT', 'http://sandbox:8194')-CODE_EXECUTION_API_KEY = os.environ.get('CODE_EXECUTION_API_KEY', 'dify-sandbox')+CODE_EXECUTION_ENDPOINT = dify_config.CODE_EXECUTION_ENDPOINT+CODE_EXECUTION_API_KEY = dify_config.CODE_EXECUTION_API_KEYCODE_EXECUTION_TIMEOUT= (10, 60)diff --git a/api/core/model_runtime/model_providers/zhipuai/zhipuai_sdk/_client.py b/api/core/model_runtime/model_providers/zhipuai/zhipuai_sdk/_client.pyindex 29b17463511..6588d1dd684 100644--- a/api/core/model_runtime/model_providers/zhipuai/zhipuai_sdk/_client.py+++ b/api/core/model_runtime/model_providers/zhipuai/zhipuai_sdk/_client.py@@ -29,10 +29,8 @@ class ZhipuAI(HttpClient):http_client: httpx.Client | None = None,custom_headers: Mapping[str, str] | None = None) -> None:- # if api_key is None:- # api_key = os.environ.get("ZHIPUAI_API_KEY")if api_key is None:- raise ZhipuAIError("未提供api_key,请通过参数或环境变量提供")+ raise ZhipuAIError("No api_key provided, please provide it through parameters or environment variables")self.api_key = api_keyif base_url is None:diff --git a/api/core/workflow/nodes/code/code_node.py b/api/core/workflow/nodes/code/code_node.pyindex 610a23e704d..e15c1c6f875 100644--- a/api/core/workflow/nodes/code/code_node.py+++ b/api/core/workflow/nodes/code/code_node.py@@ -1,6 +1,6 @@-import osfrom typing import Optional, Union, cast+from configs import dify_configfrom core.helper.code_executor.code_executor import CodeExecutionException, CodeExecutor, CodeLanguagefrom core.helper.code_executor.code_node_provider import CodeNodeProviderfrom core.helper.code_executor.javascript.javascript_code_provider import JavascriptCodeProvider@@ -11,14 +11,14 @@ from core.workflow.nodes.base_node import BaseNodefrom core.workflow.nodes.code.entities import CodeNodeDatafrom models.workflow import WorkflowNodeExecutionStatus-MAX_NUMBER = int(os.environ.get('CODE_MAX_NUMBER', '9223372036854775807'))-MIN_NUMBER = int(os.environ.get('CODE_MIN_NUMBER', '-9223372036854775808'))+MAX_NUMBER = dify_config.CODE_MAX_NUMBER+MIN_NUMBER = dify_config.CODE_MIN_NUMBERMAX_PRECISION = 20MAX_DEPTH = 5-MAX_STRING_LENGTH = int(os.environ.get('CODE_MAX_STRING_LENGTH', '80000'))-MAX_STRING_ARRAY_LENGTH = int(os.environ.get('CODE_MAX_STRING_ARRAY_LENGTH', '30'))-MAX_OBJECT_ARRAY_LENGTH = int(os.environ.get('CODE_MAX_OBJECT_ARRAY_LENGTH', '30'))-MAX_NUMBER_ARRAY_LENGTH = int(os.environ.get('CODE_MAX_NUMBER_ARRAY_LENGTH', '1000'))+MAX_STRING_LENGTH = dify_config.CODE_MAX_STRING_LENGTH+MAX_STRING_ARRAY_LENGTH = dify_config.CODE_MAX_STRING_ARRAY_LENGTH+MAX_OBJECT_ARRAY_LENGTH = dify_config.CODE_MAX_OBJECT_ARRAY_LENGTH+MAX_NUMBER_ARRAY_LENGTH = dify_config.CODE_MAX_NUMBER_ARRAY_LENGTHclass CodeNode(BaseNode):diff --git a/api/core/workflow/nodes/http_request/entities.py b/api/core/workflow/nodes/http_request/entities.pyindex f4d6afa6ed5..65451452c84 100644--- a/api/core/workflow/nodes/http_request/entities.py+++ b/api/core/workflow/nodes/http_request/entities.py@@ -1,13 +1,13 @@-import osfrom typing import Literal, Optional, Unionfrom pydantic import BaseModel, ValidationInfo, field_validator+from configs import dify_configfrom core.workflow.entities.base_node_data_entities import BaseNodeData-MAX_CONNECT_TIMEOUT = int(os.environ.get('HTTP_REQUEST_MAX_CONNECT_TIMEOUT', '300'))-MAX_READ_TIMEOUT = int(os.environ.get('HTTP_REQUEST_MAX_READ_TIMEOUT', '600'))-MAX_WRITE_TIMEOUT = int(os.environ.get('HTTP_REQUEST_MAX_WRITE_TIMEOUT', '600'))+MAX_CONNECT_TIMEOUT = dify_config.HTTP_REQUEST_MAX_CONNECT_TIMEOUT+MAX_READ_TIMEOUT = dify_config.HTTP_REQUEST_MAX_READ_TIMEOUT+MAX_WRITE_TIMEOUT = dify_config.HTTP_REQUEST_MAX_WRITE_TIMEOUTclass HttpRequestNodeAuthorizationConfig(BaseModel):diff --git a/api/core/workflow/nodes/http_request/http_executor.py b/api/core/workflow/nodes/http_request/http_executor.pyindex d69b323bbb4..902d821e408 100644--- a/api/core/workflow/nodes/http_request/http_executor.py+++ b/api/core/workflow/nodes/http_request/http_executor.py@@ -1,5 +1,4 @@import json-import osfrom copy import deepcopyfrom random import randintfrom typing import Any, Optional, Union@@ -8,6 +7,7 @@ from urllib.parse import urlencodeimport httpximport core.helper.ssrf_proxy as ssrf_proxy+from configs import dify_configfrom core.workflow.entities.variable_entities import VariableSelectorfrom core.workflow.entities.variable_pool import ValueType, VariablePoolfrom core.workflow.nodes.http_request.entities import (@@ -18,10 +18,10 @@ from core.workflow.nodes.http_request.entities import ()from core.workflow.utils.variable_template_parser import VariableTemplateParser-MAX_BINARY_SIZE = int(os.environ.get('HTTP_REQUEST_NODE_MAX_BINARY_SIZE', 1024 * 1024 * 10)) # 10MB-READABLE_MAX_BINARY_SIZE = f'{MAX_BINARY_SIZE / 1024 / 1024:.2f}MB'-MAX_TEXT_SIZE = int(os.environ.get('HTTP_REQUEST_NODE_MAX_TEXT_SIZE', 1024 * 1024)) # 1MB-READABLE_MAX_TEXT_SIZE = f'{MAX_TEXT_SIZE / 1024 / 1024:.2f}MB'+MAX_BINARY_SIZE = dify_config.HTTP_REQUEST_NODE_MAX_BINARY_SIZE+READABLE_MAX_BINARY_SIZE = dify_config.HTTP_REQUEST_NODE_READABLE_MAX_BINARY_SIZE+MAX_TEXT_SIZE = dify_config.HTTP_REQUEST_NODE_MAX_TEXT_SIZE+READABLE_MAX_TEXT_SIZE = dify_config.HTTP_REQUEST_NODE_READABLE_MAX_TEXT_SIZEclass HttpExecutorResponse: