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
chore: refurish python code by applying Pylint linter rules (#8322)
Bowen Lianga1104ab97ee5
diff --git a/api/app.py b/api/app.pyindex ad219ca0d67..91a49337fcc 100644--- a/api/app.py+++ b/api/app.py@@ -164,7 +164,7 @@ def initialize_extensions(app):@login_manager.request_loaderdef load_user_from_request(request_from_flask_login):"""Load user based on the request."""- if request.blueprint not in ["console", "inner_api"]:+ if request.blueprint not in {"console", "inner_api"}:return None# Check if the user_id contains a dot, indicating the old formatauth_header = request.headers.get("Authorization", "")diff --git a/api/commands.py b/api/commands.pyindex 887270b43e6..3a6b4963cfa 100644--- a/api/commands.py+++ b/api/commands.py@@ -140,9 +140,9 @@ def reset_encrypt_key_pair():@click.command("vdb-migrate", help="migrate vector db.")@click.option("--scope", default="all", prompt=False, help="The scope of vector database to migrate, Default is All.")def vdb_migrate(scope: str):- if scope in ["knowledge", "all"]:+ if scope in {"knowledge", "all"}:migrate_knowledge_vector_database()- if scope in ["annotation", "all"]:+ if scope in {"annotation", "all"}:migrate_annotation_vector_database()diff --git a/api/controllers/console/app/audio.py b/api/controllers/console/app/audio.pyindex 7332758e83c..c1ef05a4886 100644--- a/api/controllers/console/app/audio.py+++ b/api/controllers/console/app/audio.py@@ -94,7 +94,7 @@ class ChatMessageTextApi(Resource):message_id = args.get("message_id", None)text = args.get("text", None)if (- app_model.mode in [AppMode.ADVANCED_CHAT.value, AppMode.WORKFLOW.value]+ app_model.mode in {AppMode.ADVANCED_CHAT.value, AppMode.WORKFLOW.value}and app_model.workflowand app_model.workflow.features_dict):diff --git a/api/controllers/console/auth/oauth.py b/api/controllers/console/auth/oauth.pyindex 1df0f5de9d5..ad0c0580aea 100644--- a/api/controllers/console/auth/oauth.py+++ b/api/controllers/console/auth/oauth.py@@ -71,7 +71,7 @@ class OAuthCallback(Resource):account = _generate_account(provider, user_info)# Check account status- if account.status == AccountStatus.BANNED.value or account.status == AccountStatus.CLOSED.value:+ if account.status in {AccountStatus.BANNED.value, AccountStatus.CLOSED.value}:return {"error": "Account is banned or closed."}, 403if account.status == AccountStatus.PENDING.value:diff --git a/api/controllers/console/datasets/datasets_document.py b/api/controllers/console/datasets/datasets_document.pyindex 076f3cd44d5..829ef11e521 100644--- a/api/controllers/console/datasets/datasets_document.py+++ b/api/controllers/console/datasets/datasets_document.py@@ -354,7 +354,7 @@ class DocumentIndexingEstimateApi(DocumentResource):document_id = str(document_id)document = self.get_document(dataset_id, document_id)- if document.indexing_status in ["completed", "error"]:+ if document.indexing_status in {"completed", "error"}:raise DocumentAlreadyFinishedError()data_process_rule = document.dataset_process_rule@@ -421,7 +421,7 @@ class DocumentBatchIndexingEstimateApi(DocumentResource):info_list = []extract_settings = []for document in documents:- if document.indexing_status in ["completed", "error"]:+ if document.indexing_status in {"completed", "error"}:raise DocumentAlreadyFinishedError()data_source_info = document.data_source_info_dict# format document files info@@ -665,7 +665,7 @@ class DocumentProcessingApi(DocumentResource):db.session.commit()elif action == "resume":- if document.indexing_status not in ["paused", "error"]:+ if document.indexing_status not in {"paused", "error"}:raise InvalidActionError("Document not in paused or error state.")document.paused_by = Nonediff --git a/api/controllers/console/explore/audio.py b/api/controllers/console/explore/audio.pyindex 2eb7e044903..9690677f61b 100644--- a/api/controllers/console/explore/audio.py+++ b/api/controllers/console/explore/audio.py@@ -81,7 +81,7 @@ class ChatTextApi(InstalledAppResource):message_id = args.get("message_id", None)text = args.get("text", None)if (- app_model.mode in [AppMode.ADVANCED_CHAT.value, AppMode.WORKFLOW.value]+ app_model.mode in {AppMode.ADVANCED_CHAT.value, AppMode.WORKFLOW.value}and app_model.workflowand app_model.workflow.features_dict):diff --git a/api/controllers/console/explore/completion.py b/api/controllers/console/explore/completion.pyindex c039e8bca52..f4646920982 100644--- a/api/controllers/console/explore/completion.py+++ b/api/controllers/console/explore/completion.py@@ -92,7 +92,7 @@ class ChatApi(InstalledAppResource):def post(self, installed_app):app_model = installed_app.appapp_mode = AppMode.value_of(app_model.mode)- if app_mode not in [AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT]:+ if app_mode not in {AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT}:raise NotChatAppError()parser = reqparse.RequestParser()@@ -140,7 +140,7 @@ class ChatStopApi(InstalledAppResource):def post(self, installed_app, task_id):app_model = installed_app.appapp_mode = AppMode.value_of(app_model.mode)- if app_mode not in [AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT]:+ if app_mode not in {AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT}:raise NotChatAppError()AppQueueManager.set_stop_flag(task_id, InvokeFrom.EXPLORE, current_user.id)diff --git a/api/controllers/console/explore/conversation.py b/api/controllers/console/explore/conversation.pyindex 2918024b64c..6f9d7769b94 100644--- a/api/controllers/console/explore/conversation.py+++ b/api/controllers/console/explore/conversation.py@@ -20,7 +20,7 @@ class ConversationListApi(InstalledAppResource):def get(self, installed_app):app_model = installed_app.appapp_mode = AppMode.value_of(app_model.mode)- if app_mode not in [AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT]:+ if app_mode not in {AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT}:raise NotChatAppError()parser = reqparse.RequestParser()@@ -50,7 +50,7 @@ class ConversationApi(InstalledAppResource):def delete(self, installed_app, c_id):app_model = installed_app.appapp_mode = AppMode.value_of(app_model.mode)- if app_mode not in [AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT]:+ if app_mode not in {AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT}:raise NotChatAppError()conversation_id = str(c_id)@@ -68,7 +68,7 @@ class ConversationRenameApi(InstalledAppResource):def post(self, installed_app, c_id):app_model = installed_app.appapp_mode = AppMode.value_of(app_model.mode)- if app_mode not in [AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT]:+ if app_mode not in {AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT}:raise NotChatAppError()conversation_id = str(c_id)@@ -90,7 +90,7 @@ class ConversationPinApi(InstalledAppResource):def patch(self, installed_app, c_id):app_model = installed_app.appapp_mode = AppMode.value_of(app_model.mode)- if app_mode not in [AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT]:+ if app_mode not in {AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT}:raise NotChatAppError()conversation_id = str(c_id)@@ -107,7 +107,7 @@ class ConversationUnPinApi(InstalledAppResource):def patch(self, installed_app, c_id):app_model = installed_app.appapp_mode = AppMode.value_of(app_model.mode)- if app_mode not in [AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT]:+ if app_mode not in {AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT}:raise NotChatAppError()conversation_id = str(c_id)diff --git a/api/controllers/console/explore/installed_app.py b/api/controllers/console/explore/installed_app.pyindex 3f1e64a2478..408afc33a0c 100644--- a/api/controllers/console/explore/installed_app.py+++ b/api/controllers/console/explore/installed_app.py@@ -31,7 +31,7 @@ class InstalledAppsListApi(Resource):"app_owner_tenant_id": installed_app.app_owner_tenant_id,"is_pinned": installed_app.is_pinned,"last_used_at": installed_app.last_used_at,- "editable": current_user.role in ["owner", "admin"],+ "editable": current_user.role in {"owner", "admin"},"uninstallable": current_tenant_id == installed_app.app_owner_tenant_id,}for installed_app in installed_appsdiff --git a/api/controllers/console/explore/message.py b/api/controllers/console/explore/message.pyindex f5eb1851725..0e0238556cf 100644--- a/api/controllers/console/explore/message.py+++ b/api/controllers/console/explore/message.py@@ -40,7 +40,7 @@ class MessageListApi(InstalledAppResource):app_model = installed_app.appapp_mode = AppMode.value_of(app_model.mode)- if app_mode not in [AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT]:+ if app_mode not in {AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT}:raise NotChatAppError()parser = reqparse.RequestParser()@@ -125,7 +125,7 @@ class MessageSuggestedQuestionApi(InstalledAppResource):def get(self, installed_app, message_id):app_model = installed_app.appapp_mode = AppMode.value_of(app_model.mode)- if app_mode not in [AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT]:+ if app_mode not in {AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT}:raise NotChatAppError()message_id = str(message_id)diff --git a/api/controllers/console/explore/parameter.py b/api/controllers/console/explore/parameter.pyindex ad55b040436..aab7dd78883 100644--- a/api/controllers/console/explore/parameter.py+++ b/api/controllers/console/explore/parameter.py@@ -43,7 +43,7 @@ class AppParameterApi(InstalledAppResource):"""Retrieve app parameters."""app_model = installed_app.app- if app_model.mode in [AppMode.ADVANCED_CHAT.value, AppMode.WORKFLOW.value]:+ if app_model.mode in {AppMode.ADVANCED_CHAT.value, AppMode.WORKFLOW.value}:workflow = app_model.workflowif workflow is None:raise AppUnavailableError()diff --git a/api/controllers/console/workspace/workspace.py b/api/controllers/console/workspace/workspace.pyindex 623f0b8b74d..af3ebc099b1 100644--- a/api/controllers/console/workspace/workspace.py+++ b/api/controllers/console/workspace/workspace.py@@ -194,7 +194,7 @@ class WebappLogoWorkspaceApi(Resource):raise TooManyFilesError()extension = file.filename.split(".")[-1]- if extension.lower() not in ["svg", "png"]:+ if extension.lower() not in {"svg", "png"}:raise UnsupportedFileTypeError()try:diff --git a/api/controllers/service_api/app/app.py b/api/controllers/service_api/app/app.pyindex ecc2d73deb4..f7c091217b4 100644--- a/api/controllers/service_api/app/app.py+++ b/api/controllers/service_api/app/app.py@@ -42,7 +42,7 @@ class AppParameterApi(Resource):@marshal_with(parameters_fields)def get(self, app_model: App):"""Retrieve app parameters."""- if app_model.mode in [AppMode.ADVANCED_CHAT.value, AppMode.WORKFLOW.value]:+ if app_model.mode in {AppMode.ADVANCED_CHAT.value, AppMode.WORKFLOW.value}:workflow = app_model.workflowif workflow is None:raise AppUnavailableError()diff --git a/api/controllers/service_api/app/audio.py b/api/controllers/service_api/app/audio.pyindex 8d8ca8d78c0..5db41636471 100644--- a/api/controllers/service_api/app/audio.py+++ b/api/controllers/service_api/app/audio.py@@ -79,7 +79,7 @@ class TextApi(Resource):message_id = args.get("message_id", None)text = args.get("text", None)if (- app_model.mode in [AppMode.ADVANCED_CHAT.value, AppMode.WORKFLOW.value]+ app_model.mode in {AppMode.ADVANCED_CHAT.value, AppMode.WORKFLOW.value}and app_model.workflowand app_model.workflow.features_dict):diff --git a/api/controllers/service_api/app/completion.py b/api/controllers/service_api/app/completion.pyindex f1771baf314..8d8e356c4cb 100644--- a/api/controllers/service_api/app/completion.py+++ b/api/controllers/service_api/app/completion.py@@ -96,7 +96,7 @@ class ChatApi(Resource):@validate_app_token(fetch_user_arg=FetchUserArg(fetch_from=WhereisUserArg.JSON, required=True))def post(self, app_model: App, end_user: EndUser):app_mode = AppMode.value_of(app_model.mode)- if app_mode not in [AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT]:+ if app_mode not in {AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT}:raise NotChatAppError()parser = reqparse.RequestParser()@@ -144,7 +144,7 @@ class ChatStopApi(Resource):@validate_app_token(fetch_user_arg=FetchUserArg(fetch_from=WhereisUserArg.JSON, required=True))def post(self, app_model: App, end_user: EndUser, task_id):app_mode = AppMode.value_of(app_model.mode)- if app_mode not in [AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT]:+ if app_mode not in {AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT}:raise NotChatAppError()AppQueueManager.set_stop_flag(task_id, InvokeFrom.SERVICE_API, end_user.id)diff --git a/api/controllers/service_api/app/conversation.py b/api/controllers/service_api/app/conversation.pyindex 734027a1c51..527ef4ecd36 100644--- a/api/controllers/service_api/app/conversation.py+++ b/api/controllers/service_api/app/conversation.py@@ -18,7 +18,7 @@ class ConversationApi(Resource):@marshal_with(conversation_infinite_scroll_pagination_fields)def get(self, app_model: App, end_user: EndUser):app_mode = AppMode.value_of(app_model.mode)- if app_mode not in [AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT]:+ if app_mode not in {AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT}:raise NotChatAppError()parser = reqparse.RequestParser()@@ -52,7 +52,7 @@ class ConversationDetailApi(Resource):@marshal_with(simple_conversation_fields)def delete(self, app_model: App, end_user: EndUser, c_id):app_mode = AppMode.value_of(app_model.mode)- if app_mode not in [AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT]:+ if app_mode not in {AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT}:raise NotChatAppError()conversation_id = str(c_id)@@ -69,7 +69,7 @@ class ConversationRenameApi(Resource):@marshal_with(simple_conversation_fields)def post(self, app_model: App, end_user: EndUser, c_id):app_mode = AppMode.value_of(app_model.mode)- if app_mode not in [AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT]:+ if app_mode not in {AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT}:raise NotChatAppError()conversation_id = str(c_id)diff --git a/api/controllers/service_api/app/message.py b/api/controllers/service_api/app/message.pyindex b39aaf7dd80..e54e6f4903d 100644--- a/api/controllers/service_api/app/message.py+++ b/api/controllers/service_api/app/message.py@@ -76,7 +76,7 @@ class MessageListApi(Resource):@marshal_with(message_infinite_scroll_pagination_fields)def get(self, app_model: App, end_user: EndUser):app_mode = AppMode.value_of(app_model.mode)- if app_mode not in [AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT]:+ if app_mode not in {AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT}:raise NotChatAppError()parser = reqparse.RequestParser()@@ -117,7 +117,7 @@ class MessageSuggestedApi(Resource):def get(self, app_model: App, end_user: EndUser, message_id):message_id = str(message_id)app_mode = AppMode.value_of(app_model.mode)- if app_mode not in [AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT]:+ if app_mode not in {AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT}:raise NotChatAppError()try:diff --git a/api/controllers/web/app.py b/api/controllers/web/app.pyindex aabca93338f..20b4e4674cc 100644--- a/api/controllers/web/app.py+++ b/api/controllers/web/app.py@@ -41,7 +41,7 @@ class AppParameterApi(WebApiResource):@marshal_with(parameters_fields)def get(self, app_model: App, end_user):"""Retrieve app parameters."""- if app_model.mode in [AppMode.ADVANCED_CHAT.value, AppMode.WORKFLOW.value]:+ if app_model.mode in {AppMode.ADVANCED_CHAT.value, AppMode.WORKFLOW.value}:workflow = app_model.workflowif workflow is None:raise AppUnavailableError()diff --git a/api/controllers/web/audio.py b/api/controllers/web/audio.pyindex 49c467dbe18..23550efe2e2 100644--- a/api/controllers/web/audio.py+++ b/api/controllers/web/audio.py@@ -78,7 +78,7 @@ class TextApi(WebApiResource):message_id = args.get("message_id", None)text = args.get("text", None)if (- app_model.mode in [AppMode.ADVANCED_CHAT.value, AppMode.WORKFLOW.value]+ app_model.mode in {AppMode.ADVANCED_CHAT.value, AppMode.WORKFLOW.value}and app_model.workflowand app_model.workflow.features_dict):diff --git a/api/controllers/web/completion.py b/api/controllers/web/completion.pyindex 0837eedfb06..115492b7966 100644--- a/api/controllers/web/completion.py+++ b/api/controllers/web/completion.py@@ -87,7 +87,7 @@ class CompletionStopApi(WebApiResource):class ChatApi(WebApiResource):def post(self, app_model, end_user):app_mode = AppMode.value_of(app_model.mode)- if app_mode not in [AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT]:+ if app_mode not in {AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT}:raise NotChatAppError()parser = reqparse.RequestParser()@@ -136,7 +136,7 @@ class ChatApi(WebApiResource):class ChatStopApi(WebApiResource):def post(self, app_model, end_user, task_id):app_mode = AppMode.value_of(app_model.mode)- if app_mode not in [AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT]:+ if app_mode not in {AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT}:raise NotChatAppError()AppQueueManager.set_stop_flag(task_id, InvokeFrom.WEB_APP, end_user.id)diff --git a/api/controllers/web/conversation.py b/api/controllers/web/conversation.pyindex 6bbfa94c275..c3b0cd4f44b 100644--- a/api/controllers/web/conversation.py+++ b/api/controllers/web/conversation.py@@ -18,7 +18,7 @@ class ConversationListApi(WebApiResource):@marshal_with(conversation_infinite_scroll_pagination_fields)def get(self, app_model, end_user):app_mode = AppMode.value_of(app_model.mode)- if app_mode not in [AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT]:+ if app_mode not in {AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT}:raise NotChatAppError()parser = reqparse.RequestParser()@@ -56,7 +56,7 @@ class ConversationListApi(WebApiResource):class ConversationApi(WebApiResource):def delete(self, app_model, end_user, c_id):app_mode = AppMode.value_of(app_model.mode)- if app_mode not in [AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT]:+ if app_mode not in {AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT}:raise NotChatAppError()conversation_id = str(c_id)@@ -73,7 +73,7 @@ class ConversationRenameApi(WebApiResource):@marshal_with(simple_conversation_fields)def post(self, app_model, end_user, c_id):app_mode = AppMode.value_of(app_model.mode)- if app_mode not in [AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT]:+ if app_mode not in {AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT}:raise NotChatAppError()conversation_id = str(c_id)@@ -92,7 +92,7 @@ class ConversationRenameApi(WebApiResource):class ConversationPinApi(WebApiResource):def patch(self, app_model, end_user, c_id):app_mode = AppMode.value_of(app_model.mode)- if app_mode not in [AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT]:+ if app_mode not in {AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT}:raise NotChatAppError()conversation_id = str(c_id)@@ -108,7 +108,7 @@ class ConversationPinApi(WebApiResource):class ConversationUnPinApi(WebApiResource):def patch(self, app_model, end_user, c_id):app_mode = AppMode.value_of(app_model.mode)- if app_mode not in [AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT]:+ if app_mode not in {AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT}:raise NotChatAppError()conversation_id = str(c_id)diff --git a/api/controllers/web/message.py b/api/controllers/web/message.pyindex 56aaaa930a4..0d4047f4efb 100644--- a/api/controllers/web/message.py+++ b/api/controllers/web/message.py@@ -78,7 +78,7 @@ class MessageListApi(WebApiResource):@marshal_with(message_infinite_scroll_pagination_fields)def get(self, app_model, end_user):app_mode = AppMode.value_of(app_model.mode)- if app_mode not in [AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT]:+ if app_mode not in {AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT}:raise NotChatAppError()parser = reqparse.RequestParser()@@ -160,7 +160,7 @@ class MessageMoreLikeThisApi(WebApiResource):class MessageSuggestedQuestionApi(WebApiResource):def get(self, app_model, end_user, message_id):app_mode = AppMode.value_of(app_model.mode)- if app_mode not in [AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT]:+ if app_mode not in {AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT}:raise NotCompletionAppError()message_id = str(message_id)diff --git a/api/core/agent/output_parser/cot_output_parser.py b/api/core/agent/output_parser/cot_output_parser.pyindex 1a161677dda..d04e38777a5 100644--- a/api/core/agent/output_parser/cot_output_parser.py+++ b/api/core/agent/output_parser/cot_output_parser.py@@ -90,7 +90,7 @@ class CotAgentOutputParser:if not in_code_block and not in_json:if delta.lower() == action_str[action_idx] and action_idx == 0:- if last_character not in ["\n", " ", ""]:+ if last_character not in {"\n", " ", ""}:index += stepsyield deltacontinue@@ -117,7 +117,7 @@ class CotAgentOutputParser:action_idx = 0if delta.lower() == thought_str[thought_idx] and thought_idx == 0:- if last_character not in ["\n", " ", ""]:+ if last_character not in {"\n", " ", ""}:index += stepsyield deltacontinuediff --git a/api/core/app/app_config/base_app_config_manager.py b/api/core/app/app_config/base_app_config_manager.pyindex 0fd2a779a48..24d80f9cdd7 100644--- a/api/core/app/app_config/base_app_config_manager.py+++ b/api/core/app/app_config/base_app_config_manager.py@@ -29,7 +29,7 @@ class BaseAppConfigManager:additional_features.show_retrieve_source = RetrievalResourceConfigManager.convert(config=config_dict)additional_features.file_upload = FileUploadConfigManager.convert(- config=config_dict, is_vision=app_mode in [AppMode.CHAT, AppMode.COMPLETION, AppMode.AGENT_CHAT]+ config=config_dict, is_vision=app_mode in {AppMode.CHAT, AppMode.COMPLETION, AppMode.AGENT_CHAT})additional_features.opening_statement, additional_features.suggested_questions = (diff --git a/api/core/app/app_config/easy_ui_based_app/agent/manager.py b/api/core/app/app_config/easy_ui_based_app/agent/manager.pyindex 6e89f19508c..f503543d7bd 100644--- a/api/core/app/app_config/easy_ui_based_app/agent/manager.py+++ b/api/core/app/app_config/easy_ui_based_app/agent/manager.py@@ -18,7 +18,7 @@ class AgentConfigManager:if agent_strategy == "function_call":strategy = AgentEntity.Strategy.FUNCTION_CALLING- elif agent_strategy == "cot" or agent_strategy == "react":+ elif agent_strategy in {"cot", "react"}:strategy = AgentEntity.Strategy.CHAIN_OF_THOUGHTelse:# old configs, try to detect default strategy@@ -43,10 +43,10 @@ class AgentConfigManager:agent_tools.append(AgentToolEntity(**agent_tool_properties))- if "strategy" in config["agent_mode"] and config["agent_mode"]["strategy"] not in [+ if "strategy" in config["agent_mode"] and config["agent_mode"]["strategy"] not in {"react_router","router",- ]:+ }:agent_prompt = agent_dict.get("prompt", None) or {}# check model modemodel_mode = config.get("model", {}).get("mode", "completion")diff --git a/api/core/app/app_config/easy_ui_based_app/dataset/manager.py b/api/core/app/app_config/easy_ui_based_app/dataset/manager.pyindex ff131b62e27..a22395b8e39 100644--- a/api/core/app/app_config/easy_ui_based_app/dataset/manager.py+++ b/api/core/app/app_config/easy_ui_based_app/dataset/manager.py@@ -167,7 +167,7 @@ class DatasetConfigManager:config["agent_mode"]["strategy"] = PlanningStrategy.ROUTER.valuehas_datasets = False- if config["agent_mode"]["strategy"] in [PlanningStrategy.ROUTER.value, PlanningStrategy.REACT_ROUTER.value]:+ if config["agent_mode"]["strategy"] in {PlanningStrategy.ROUTER.value, PlanningStrategy.REACT_ROUTER.value}:for tool in config["agent_mode"]["tools"]:key = list(tool.keys())[0]if key == "dataset":diff --git a/api/core/app/app_config/easy_ui_based_app/variables/manager.py b/api/core/app/app_config/easy_ui_based_app/variables/manager.pyindex e70522f21de..a1bfde32085 100644--- a/api/core/app/app_config/easy_ui_based_app/variables/manager.py+++ b/api/core/app/app_config/easy_ui_based_app/variables/manager.py@@ -42,12 +42,12 @@ class BasicVariablesConfigManager:variable=variable["variable"], type=variable["type"], config=variable["config"]))- elif variable_type in [+ elif variable_type in {VariableEntityType.TEXT_INPUT,VariableEntityType.PARAGRAPH,VariableEntityType.NUMBER,VariableEntityType.SELECT,- ]:+ }:variable = variables[variable_type]variable_entities.append(VariableEntity(@@ -97,7 +97,7 @@ class BasicVariablesConfigManager:variables = []for item in config["user_input_form"]:key = list(item.keys())[0]- if key not in ["text-input", "select", "paragraph", "number", "external_data_tool"]:+ if key not in {"text-input", "select", "paragraph", "number", "external_data_tool"}:raise ValueError("Keys in user_input_form list can only be 'text-input', 'paragraph' or 'select'")form_item = item[key]diff --git a/api/core/app/app_config/features/file_upload/manager.py b/api/core/app/app_config/features/file_upload/manager.pyindex 5f7fc99151d..7a275cb532f 100644--- a/api/core/app/app_config/features/file_upload/manager.py+++ b/api/core/app/app_config/features/file_upload/manager.py@@ -54,14 +54,14 @@ class FileUploadConfigManager:if is_vision:detail = config["file_upload"]["image"]["detail"]- if detail not in ["high", "low"]:+ if detail not in {"high", "low"}:raise ValueError("detail must be in ['high', 'low']")transfer_methods = config["file_upload"]["image"]["transfer_methods"]if not isinstance(transfer_methods, list):raise ValueError("transfer_methods must be of list type")for method in transfer_methods:- if method not in ["remote_url", "local_file"]:+ if method not in {"remote_url", "local_file"}:raise ValueError("transfer_methods must be in ['remote_url', 'local_file']")return config, ["file_upload"]diff --git a/api/core/app/apps/advanced_chat/app_runner.py b/api/core/app/apps/advanced_chat/app_runner.pyindex c4cdba64419..1bca1e1b71a 100644--- a/api/core/app/apps/advanced_chat/app_runner.py+++ b/api/core/app/apps/advanced_chat/app_runner.py@@ -73,7 +73,7 @@ class AdvancedChatAppRunner(WorkflowBasedAppRunner):raise ValueError("Workflow not initialized")user_id = None- if self.application_generate_entity.invoke_from in [InvokeFrom.WEB_APP, InvokeFrom.SERVICE_API]:+ if self.application_generate_entity.invoke_from in {InvokeFrom.WEB_APP, InvokeFrom.SERVICE_API}:end_user = db.session.query(EndUser).filter(EndUser.id == self.application_generate_entity.user_id).first()if end_user:user_id = end_user.session_id@@ -175,7 +175,7 @@ class AdvancedChatAppRunner(WorkflowBasedAppRunner):user_id=self.application_generate_entity.user_id,user_from=(UserFrom.ACCOUNT- if self.application_generate_entity.invoke_from in [InvokeFrom.EXPLORE, InvokeFrom.DEBUGGER]+ if self.application_generate_entity.invoke_from in {InvokeFrom.EXPLORE, InvokeFrom.DEBUGGER}else UserFrom.END_USER),invoke_from=self.application_generate_entity.invoke_from,diff --git a/api/core/app/apps/base_app_generate_response_converter.py b/api/core/app/apps/base_app_generate_response_converter.pyindex 73025d99d05..c6855ac8549 100644--- a/api/core/app/apps/base_app_generate_response_converter.py+++ b/api/core/app/apps/base_app_generate_response_converter.py@@ -16,7 +16,7 @@ class AppGenerateResponseConverter(ABC):def convert(cls, response: Union[AppBlockingResponse, Generator[AppStreamResponse, Any, None]], invoke_from: InvokeFrom) -> dict[str, Any] | Generator[str, Any, None]:- if invoke_from in [InvokeFrom.DEBUGGER, InvokeFrom.SERVICE_API]:+ if invoke_from in {InvokeFrom.DEBUGGER, InvokeFrom.SERVICE_API}:if isinstance(response, AppBlockingResponse):return cls.convert_blocking_full_response(response)else:diff --git a/api/core/app/apps/base_app_generator.py b/api/core/app/apps/base_app_generator.pyindex ce6f7d43387..15be7000fc2 100644--- a/api/core/app/apps/base_app_generator.py+++ b/api/core/app/apps/base_app_generator.py@@ -22,11 +22,11 @@ class BaseAppGenerator:return var.default or ""if (var.type- in (+ in {VariableEntityType.TEXT_INPUT,VariableEntityType.SELECT,VariableEntityType.PARAGRAPH,- )+ }and user_input_valueand not isinstance(user_input_value, str)):@@ -44,7 +44,7 @@ class BaseAppGenerator:options = var.options or []if user_input_value not in options:raise ValueError(f"{var.variable} in input form must be one of the following: {options}")- elif var.type in (VariableEntityType.TEXT_INPUT, VariableEntityType.PARAGRAPH):+ elif var.type in {VariableEntityType.TEXT_INPUT, VariableEntityType.PARAGRAPH}:if var.max_length and user_input_value and len(user_input_value) > var.max_length:raise ValueError(f"{var.variable} in input form must be less than {var.max_length} characters")diff --git a/api/core/app/apps/base_app_queue_manager.py b/api/core/app/apps/base_app_queue_manager.pyindex f3c3199354f..4c4d282e99b 100644--- a/api/core/app/apps/base_app_queue_manager.py+++ b/api/core/app/apps/base_app_queue_manager.py@@ -32,7 +32,7 @@ class AppQueueManager:self._user_id = user_idself._invoke_from = invoke_from- user_prefix = "account" if self._invoke_from in [InvokeFrom.EXPLORE, InvokeFrom.DEBUGGER] else "end-user"+ user_prefix = "account" if self._invoke_from in {InvokeFrom.EXPLORE, InvokeFrom.DEBUGGER} else "end-user"redis_client.setex(AppQueueManager._generate_task_belong_cache_key(self._task_id), 1800, f"{user_prefix}-{self._user_id}")@@ -118,7 +118,7 @@ class AppQueueManager:if result is None:return- user_prefix = "account" if invoke_from in [InvokeFrom.EXPLORE, InvokeFrom.DEBUGGER] else "end-user"+ user_prefix = "account" if invoke_from in {InvokeFrom.EXPLORE, InvokeFrom.DEBUGGER} else "end-user"if result.decode("utf-8") != f"{user_prefix}-{user_id}":returndiff --git a/api/core/app/apps/message_based_app_generator.py b/api/core/app/apps/message_based_app_generator.pyindex f629c5c8b73..c4db95cbd0c 100644--- a/api/core/app/apps/message_based_app_generator.py+++ b/api/core/app/apps/message_based_app_generator.py@@ -148,7 +148,7 @@ class MessageBasedAppGenerator(BaseAppGenerator):# get from sourceend_user_id = Noneaccount_id = None- if application_generate_entity.invoke_from in [InvokeFrom.WEB_APP, InvokeFrom.SERVICE_API]:+ if application_generate_entity.invoke_from in {InvokeFrom.WEB_APP, InvokeFrom.SERVICE_API}:from_source = "api"end_user_id = application_generate_entity.user_idelse:@@ -165,11 +165,11 @@ class MessageBasedAppGenerator(BaseAppGenerator):model_provider = application_generate_entity.model_conf.providermodel_id = application_generate_entity.model_conf.modeloverride_model_configs = None- if app_config.app_model_config_from == EasyUIBasedAppModelConfigFrom.ARGS and app_config.app_mode in [+ if app_config.app_model_config_from == EasyUIBasedAppModelConfigFrom.ARGS and app_config.app_mode in {AppMode.AGENT_CHAT,AppMode.CHAT,AppMode.COMPLETION,- ]:+ }:override_model_configs = app_config.app_model_config_dict# get conversation introductiondiff --git a/api/core/app/apps/workflow/app_runner.py b/api/core/app/apps/workflow/app_runner.pyindex 81c8463dd54..22ec228fa79 100644--- a/api/core/app/apps/workflow/app_runner.py+++ b/api/core/app/apps/workflow/app_runner.py@@ -53,7 +53,7 @@ class WorkflowAppRunner(WorkflowBasedAppRunner):app_config = cast(WorkflowAppConfig, app_config)user_id = None- if self.application_generate_entity.invoke_from in [InvokeFrom.WEB_APP, InvokeFrom.SERVICE_API]:+ if self.application_generate_entity.invoke_from in {InvokeFrom.WEB_APP, InvokeFrom.SERVICE_API}:end_user = db.session.query(EndUser).filter(EndUser.id == self.application_generate_entity.user_id).first()if end_user:user_id = end_user.session_id@@ -113,7 +113,7 @@ class WorkflowAppRunner(WorkflowBasedAppRunner):user_id=self.application_generate_entity.user_id,user_from=(UserFrom.ACCOUNT- if self.application_generate_entity.invoke_from in [InvokeFrom.EXPLORE, InvokeFrom.DEBUGGER]+ if self.application_generate_entity.invoke_from in {InvokeFrom.EXPLORE, InvokeFrom.DEBUGGER}else UserFrom.END_USER),invoke_from=self.application_generate_entity.invoke_from,diff --git a/api/core/app/features/annotation_reply/annotation_reply.py b/api/core/app/features/annotation_reply/annotation_reply.pyindex 2e37a126c3e..77b6bb554c6 100644--- a/api/core/app/features/annotation_reply/annotation_reply.py+++ b/api/core/app/features/annotation_reply/annotation_reply.py@@ -63,7 +63,7 @@ class AnnotationReplyFeature:score = documents[0].metadata["score"]annotation = AppAnnotationService.get_annotation_by_id(annotation_id)if annotation:- if invoke_from in [InvokeFrom.SERVICE_API, InvokeFrom.WEB_APP]:+ if invoke_from in {InvokeFrom.SERVICE_API, InvokeFrom.WEB_APP}:from_source = "api"else:from_source = "console"diff --git a/api/core/app/task_pipeline/easy_ui_based_generate_task_pipeline.py b/api/core/app/task_pipeline/easy_ui_based_generate_task_pipeline.pyindex 659503301e5..8f834b6458e 100644--- a/api/core/app/task_pipeline/easy_ui_based_generate_task_pipeline.py+++ b/api/core/app/task_pipeline/easy_ui_based_generate_task_pipeline.py@@ -372,7 +372,7 @@ class EasyUIBasedGenerateTaskPipeline(BasedGenerateTaskPipeline, MessageCycleManself._message,application_generate_entity=self._application_generate_entity,conversation=self._conversation,- is_first_message=self._application_generate_entity.app_config.app_mode in [AppMode.AGENT_CHAT, AppMode.CHAT]+ is_first_message=self._application_generate_entity.app_config.app_mode in {AppMode.AGENT_CHAT, AppMode.CHAT}and self._application_generate_entity.conversation_id is None,extras=self._application_generate_entity.extras,)diff --git a/api/core/app/task_pipeline/workflow_cycle_manage.py b/api/core/app/task_pipeline/workflow_cycle_manage.pyindex a030d5dcbf3..f10189798f8 100644--- a/api/core/app/task_pipeline/workflow_cycle_manage.py+++ b/api/core/app/task_pipeline/workflow_cycle_manage.py@@ -383,7 +383,7 @@ class WorkflowCycleManage::param workflow_node_execution: workflow node execution:return:"""- if workflow_node_execution.node_type in [NodeType.ITERATION.value, NodeType.LOOP.value]:+ if workflow_node_execution.node_type in {NodeType.ITERATION.value, NodeType.LOOP.value}:return Noneresponse = NodeStartStreamResponse(@@ -430,7 +430,7 @@ class WorkflowCycleManage::param workflow_node_execution: workflow node execution:return:"""- if workflow_node_execution.node_type in [NodeType.ITERATION.value, NodeType.LOOP.value]:+ if workflow_node_execution.node_type in {NodeType.ITERATION.value, NodeType.LOOP.value}:return Nonereturn NodeFinishStreamResponse(diff --git a/api/core/callback_handler/index_tool_callback_handler.py b/api/core/callback_handler/index_tool_callback_handler.pyindex 6d5393ce5c6..7cf472d984a 100644--- a/api/core/callback_handler/index_tool_callback_handler.py+++ b/api/core/callback_handler/index_tool_callback_handler.py@@ -29,7 +29,7 @@ class DatasetIndexToolCallbackHandler:source="app",source_app_id=self._app_id,created_by_role=(- "account" if self._invoke_from in [InvokeFrom.EXPLORE, InvokeFrom.DEBUGGER] else "end_user"+ "account" if self._invoke_from in {InvokeFrom.EXPLORE, InvokeFrom.DEBUGGER} else "end_user"),created_by=self._user_id,)diff --git a/api/core/indexing_runner.py b/api/core/indexing_runner.pyindex eeb1dbfda0b..af20df41b1f 100644--- a/api/core/indexing_runner.py+++ b/api/core/indexing_runner.py@@ -292,7 +292,7 @@ class IndexingRunner:self, index_processor: BaseIndexProcessor, dataset_document: DatasetDocument, process_rule: dict) -> list[Document]:# load file- if dataset_document.data_source_type not in ["upload_file", "notion_import", "website_crawl"]:+ if dataset_document.data_source_type not in {"upload_file", "notion_import", "website_crawl"}:return []data_source_info = dataset_document.data_source_info_dictdiff --git a/api/core/memory/token_buffer_memory.py b/api/core/memory/token_buffer_memory.pyindex a14d237a12a..d3185c3b11a 100644--- a/api/core/memory/token_buffer_memory.py+++ b/api/core/memory/token_buffer_memory.py@@ -52,7 +52,7 @@ class TokenBufferMemory:files = db.session.query(MessageFile).filter(MessageFile.message_id == message.id).all()if files:file_extra_config = None- if self.conversation.mode not in [AppMode.ADVANCED_CHAT.value, AppMode.WORKFLOW.value]:+ if self.conversation.mode not in {AppMode.ADVANCED_CHAT.value, AppMode.WORKFLOW.value}:file_extra_config = FileUploadConfigManager.convert(self.conversation.model_config)else:if message.workflow_run_id:diff --git a/api/core/model_runtime/entities/model_entities.py b/api/core/model_runtime/entities/model_entities.pyindex d898ef14909..52ea787c3ad 100644--- a/api/core/model_runtime/entities/model_entities.py+++ b/api/core/model_runtime/entities/model_entities.py@@ -27,17 +27,17 @@ class ModelType(Enum)::return: model type"""- if origin_model_type == "text-generation" or origin_model_type == cls.LLM.value:+ if origin_model_type in {"text-generation", cls.LLM.value}:return cls.LLM- elif origin_model_type == "embeddings" or origin_model_type == cls.TEXT_EMBEDDING.value:+ elif origin_model_type in {"embeddings", cls.TEXT_EMBEDDING.value}:return cls.TEXT_EMBEDDING- elif origin_model_type == "reranking" or origin_model_type == cls.RERANK.value:+ elif origin_model_type in {"reranking", cls.RERANK.value}:return cls.RERANK- elif origin_model_type == "speech2text" or origin_model_type == cls.SPEECH2TEXT.value:+ elif origin_model_type in {"speech2text", cls.SPEECH2TEXT.value}:return cls.SPEECH2TEXT- elif origin_model_type == "tts" or origin_model_type == cls.TTS.value:+ elif origin_model_type in {"tts", cls.TTS.value}:return cls.TTS- elif origin_model_type == "text2img" or origin_model_type == cls.TEXT2IMG.value:+ elif origin_model_type in {"text2img", cls.TEXT2IMG.value}:return cls.TEXT2IMGelif origin_model_type == cls.MODERATION.value:return cls.MODERATIONdiff --git a/api/core/model_runtime/model_providers/anthropic/llm/llm.py b/api/core/model_runtime/model_providers/anthropic/llm/llm.pyindex ff741e02402..46e1b415b81 100644--- a/api/core/model_runtime/model_providers/anthropic/llm/llm.py+++ b/api/core/model_runtime/model_providers/anthropic/llm/llm.py@@ -494,7 +494,7 @@ class AnthropicLargeLanguageModel(LargeLanguageModel):mime_type = data_split[0].replace("data:", "")base64_data = data_split[1]- if mime_type not in ["image/jpeg", "image/png", "image/gif", "image/webp"]:+ if mime_type not in {"image/jpeg", "image/png", "image/gif", "image/webp"}:raise ValueError(f"Unsupported image type {mime_type}, "f"only support image/jpeg, image/png, image/gif, and image/webp"diff --git a/api/core/model_runtime/model_providers/azure_openai/tts/tts.py b/api/core/model_runtime/model_providers/azure_openai/tts/tts.pyindex 8db044b24dd..af178703a06 100644--- a/api/core/model_runtime/model_providers/azure_openai/tts/tts.py+++ b/api/core/model_runtime/model_providers/azure_openai/tts/tts.py@@ -85,14 +85,14 @@ class AzureOpenAIText2SpeechModel(_CommonAzureOpenAI, TTSModel):for i in range(len(sentences))]for future in futures:- yield from future.result().__enter__().iter_bytes(1024)+ yield from future.result().__enter__().iter_bytes(1024) # noqa:PLC2801else:response = client.audio.speech.with_streaming_response.create(model=model, voice=voice, response_format="mp3", input=content_text.strip())- yield from response.__enter__().iter_bytes(1024)+ yield from response.__enter__().iter_bytes(1024) # noqa:PLC2801except Exception as ex:raise InvokeBadRequestError(str(ex))diff --git a/api/core/model_runtime/model_providers/bedrock/llm/llm.py b/api/core/model_runtime/model_providers/bedrock/llm/llm.pyindex c34c20ced35..06a86069019 100644--- a/api/core/model_runtime/model_providers/bedrock/llm/llm.py+++ b/api/core/model_runtime/model_providers/bedrock/llm/llm.py@@ -454,7 +454,7 @@ class BedrockLargeLanguageModel(LargeLanguageModel):base64_data = data_split[1]image_content = base64.b64decode(base64_data)- if mime_type not in ["image/jpeg", "image/png", "image/gif", "image/webp"]:+ if mime_type not in {"image/jpeg", "image/png", "image/gif", "image/webp"}:raise ValueError(f"Unsupported image type {mime_type}, "f"only support image/jpeg, image/png, image/gif, and image/webp"@@ -886,16 +886,16 @@ class BedrockLargeLanguageModel(LargeLanguageModel):if error_code == "AccessDeniedException":return InvokeAuthorizationError(error_msg)- elif error_code in ["ResourceNotFoundException", "ValidationException"]:+ elif error_code in {"ResourceNotFoundException", "ValidationException"}:return InvokeBadRequestError(error_msg)- elif error_code in ["ThrottlingException", "ServiceQuotaExceededException"]:+ elif error_code in {"ThrottlingException", "ServiceQuotaExceededException"}:return InvokeRateLimitError(error_msg)- elif error_code in [+ elif error_code in {"ModelTimeoutException","ModelErrorException","InternalServerException","ModelNotReadyException",- ]:+ }:return InvokeServerUnavailableError(error_msg)elif error_code == "ModelStreamErrorException":return InvokeConnectionError(error_msg)diff --git a/api/core/model_runtime/model_providers/bedrock/text_embedding/text_embedding.py b/api/core/model_runtime/model_providers/bedrock/text_embedding/text_embedding.pyindex 2d898e3aaac..251170d1aec 100644--- a/api/core/model_runtime/model_providers/bedrock/text_embedding/text_embedding.py+++ b/api/core/model_runtime/model_providers/bedrock/text_embedding/text_embedding.py@@ -186,16 +186,16 @@ class BedrockTextEmbeddingModel(TextEmbeddingModel):if error_code == "AccessDeniedException":return InvokeAuthorizationError(error_msg)- elif error_code in ["ResourceNotFoundException", "ValidationException"]:+ elif error_code in {"ResourceNotFoundException", "ValidationException"}:return InvokeBadRequestError(error_msg)- elif error_code in ["ThrottlingException", "ServiceQuotaExceededException"]:+ elif error_code in {"ThrottlingException", "ServiceQuotaExceededException"}:return InvokeRateLimitError(error_msg)- elif error_code in [+ elif error_code in {"ModelTimeoutException","ModelErrorException","InternalServerException","ModelNotReadyException",- ]:+ }:return InvokeServerUnavailableError(error_msg)elif error_code == "ModelStreamErrorException":return InvokeConnectionError(error_msg)diff --git a/api/core/model_runtime/model_providers/google/llm/llm.py b/api/core/model_runtime/model_providers/google/llm/llm.pyindex b10d0edba35..3fc6787a444 100644--- a/api/core/model_runtime/model_providers/google/llm/llm.py+++ b/api/core/model_runtime/model_providers/google/llm/llm.py@@ -6,10 +6,10 @@ from collections.abc import Generatorfrom typing import Optional, Union, castimport google.ai.generativelanguage as glm-import google.api_core.exceptions as exceptionsimport google.generativeai as genai-import google.generativeai.client as clientimport requests+from google.api_core import exceptions+from google.generativeai import clientfrom google.generativeai.types import ContentType, GenerateContentResponse, HarmBlockThreshold, HarmCategoryfrom google.generativeai.types.content_types import to_partfrom PIL import Imagediff --git a/api/core/model_runtime/model_providers/huggingface_hub/llm/llm.py b/api/core/model_runtime/model_providers/huggingface_hub/llm/llm.pyindex 48ab477c50c..9d29237fdde 100644--- a/api/core/model_runtime/model_providers/huggingface_hub/llm/llm.py+++ b/api/core/model_runtime/model_providers/huggingface_hub/llm/llm.py@@ -77,7 +77,7 @@ class HuggingfaceHubLargeLanguageModel(_CommonHuggingfaceHub, LargeLanguageModelif "huggingfacehub_api_type" not in credentials:raise CredentialsValidateFailedError("Huggingface Hub Endpoint Type must be provided.")- if credentials["huggingfacehub_api_type"] not in ("inference_endpoints", "hosted_inference_api"):+ if credentials["huggingfacehub_api_type"] not in {"inference_endpoints", "hosted_inference_api"}:raise CredentialsValidateFailedError("Huggingface Hub Endpoint Type is invalid.")if "huggingfacehub_api_token" not in credentials:@@ -94,7 +94,7 @@ class HuggingfaceHubLargeLanguageModel(_CommonHuggingfaceHub, LargeLanguageModelcredentials["huggingfacehub_api_token"], model)- if credentials["task_type"] not in ("text2text-generation", "text-generation"):+ if credentials["task_type"] not in {"text2text-generation", "text-generation"}:raise CredentialsValidateFailedError("Huggingface Hub Task Type must be one of text2text-generation, text-generation.")diff --git a/api/core/model_runtime/model_providers/huggingface_tei/tei_helper.py b/api/core/model_runtime/model_providers/huggingface_tei/tei_helper.pyindex 288637495f6..81ab2492144 100644--- a/api/core/model_runtime/model_providers/huggingface_tei/tei_helper.py+++ b/api/core/model_runtime/model_providers/huggingface_tei/tei_helper.py@@ -75,7 +75,7 @@ class TeiHelper:if len(model_type.keys()) < 1:raise RuntimeError("model_type is empty")model_type = list(model_type.keys())[0]- if model_type not in ["embedding", "reranker"]:+ if model_type not in {"embedding", "reranker"}:raise RuntimeError(f"invalid model_type: {model_type}")max_input_length = response_json.get("max_input_length", 512)diff --git a/api/core/model_runtime/model_providers/minimax/llm/chat_completion.py b/api/core/model_runtime/model_providers/minimax/llm/chat_completion.pyindex 96f99c89297..88cc0e8e0f3 100644--- a/api/core/model_runtime/model_providers/minimax/llm/chat_completion.py+++ b/api/core/model_runtime/model_providers/minimax/llm/chat_completion.py@@ -100,9 +100,9 @@ class MinimaxChatCompletion:return self._handle_chat_generate_response(response)def _handle_error(self, code: int, msg: str):- if code == 1000 or code == 1001 or code == 1013 or code == 1027:+ if code in {1000, 1001, 1013, 1027}:raise InternalServerError(msg)- elif code == 1002 or code == 1039:+ elif code in {1002, 1039}:raise RateLimitReachedError(msg)elif code == 1004:raise InvalidAuthenticationError(msg)diff --git a/api/core/model_runtime/model_providers/minimax/llm/chat_completion_pro.py b/api/core/model_runtime/model_providers/minimax/llm/chat_completion_pro.pyindex 0a2a67a56d7..8b8fdbb6bdf 100644--- a/api/core/model_runtime/model_providers/minimax/llm/chat_completion_pro.py+++ b/api/core/model_runtime/model_providers/minimax/llm/chat_completion_pro.py@@ -105,9 +105,9 @@ class MinimaxChatCompletionPro:return self._handle_chat_generate_response(response)def _handle_error(self, code: int, msg: str):- if code == 1000 or code == 1001 or code == 1013 or code == 1027:+ if code in {1000, 1001, 1013, 1027}:raise InternalServerError(msg)- elif code == 1002 or code == 1039:+ elif code in {1002, 1039}:raise RateLimitReachedError(msg)elif code == 1004:raise InvalidAuthenticationError(msg)diff --git a/api/core/model_runtime/model_providers/minimax/text_embedding/text_embedding.py b/api/core/model_runtime/model_providers/minimax/text_embedding/text_embedding.pyindex 02a53708be9..76fd1342bdb 100644--- a/api/core/model_runtime/model_providers/minimax/text_embedding/text_embedding.py+++ b/api/core/model_runtime/model_providers/minimax/text_embedding/text_embedding.py@@ -114,7 +114,7 @@ class MinimaxTextEmbeddingModel(TextEmbeddingModel):raise CredentialsValidateFailedError("Invalid api key")def _handle_error(self, code: int, msg: str):- if code == 1000 or code == 1001:+ if code in {1000, 1001}:raise InternalServerError(msg)elif code == 1002:raise RateLimitReachedError(msg)diff --git a/api/core/model_runtime/model_providers/openai/llm/llm.py b/api/core/model_runtime/model_providers/openai/llm/llm.pyindex 60d69c6e472..d42fce528a8 100644--- a/api/core/model_runtime/model_providers/openai/llm/llm.py+++ b/api/core/model_runtime/model_providers/openai/llm/llm.py@@ -125,7 +125,7 @@ class OpenAILargeLanguageModel(_CommonOpenAI, LargeLanguageModel):model_mode = self.get_model_mode(base_model, credentials)# transform response format- if "response_format" in model_parameters and model_parameters["response_format"] in ["JSON", "XML"]:+ if "response_format" in model_parameters and model_parameters["response_format"] in {"JSON", "XML"}:stop = stop or []if model_mode == LLMMode.CHAT:# chat modeldiff --git a/api/core/model_runtime/model_providers/openai/tts/tts.py b/api/core/model_runtime/model_providers/openai/tts/tts.pyindex b50b43199fe..a14c91639b8 100644--- a/api/core/model_runtime/model_providers/openai/tts/tts.py+++ b/api/core/model_runtime/model_providers/openai/tts/tts.py@@ -89,14 +89,14 @@ class OpenAIText2SpeechModel(_CommonOpenAI, TTSModel):for i in range(len(sentences))]for future in futures:- yield from future.result().__enter__().iter_bytes(1024)+ yield from future.result().__enter__().iter_bytes(1024) # noqa:PLC2801else:response = client.audio.speech.with_streaming_response.create(model=model, voice=voice, response_format="mp3", input=content_text.strip())- yield from response.__enter__().iter_bytes(1024)+ yield from response.__enter__().iter_bytes(1024) # noqa:PLC2801except Exception as ex:raise InvokeBadRequestError(str(ex))diff --git a/api/core/model_runtime/model_providers/openrouter/llm/llm.py b/api/core/model_runtime/model_providers/openrouter/llm/llm.pyindex 71b5745f7d1..b6bb249a040 100644--- a/api/core/model_runtime/model_providers/openrouter/llm/llm.py+++ b/api/core/model_runtime/model_providers/openrouter/llm/llm.py@@ -12,7 +12,6 @@ class OpenRouterLargeLanguageModel(OAIAPICompatLargeLanguageModel):credentials["endpoint_url"] = "https://openrouter.ai/api/v1"credentials["mode"] = self.get_model_mode(model).valuecredentials["function_calling_type"] = "tool_call"- returndef _invoke(self,diff --git a/api/core/model_runtime/model_providers/replicate/llm/llm.py b/api/core/model_runtime/model_providers/replicate/llm/llm.pyindex daef8949fb8..3641b35dc02 100644--- a/api/core/model_runtime/model_providers/replicate/llm/llm.py+++ b/api/core/model_runtime/model_providers/replicate/llm/llm.py@@ -154,7 +154,7 @@ class ReplicateLargeLanguageModel(_CommonReplicate, LargeLanguageModel):)for key, value in input_properties:- if key not in ["system_prompt", "prompt"] and "stop" not in key:+ if key not in {"system_prompt", "prompt"} and "stop" not in key:value_type = value.get("type")if not value_type:diff --git a/api/core/model_runtime/model_providers/replicate/text_embedding/text_embedding.py b/api/core/model_runtime/model_providers/replicate/text_embedding/text_embedding.pyindex f6b7754d74f..71b6fb99c4a 100644--- a/api/core/model_runtime/model_providers/replicate/text_embedding/text_embedding.py+++ b/api/core/model_runtime/model_providers/replicate/text_embedding/text_embedding.py@@ -86,7 +86,7 @@ class ReplicateEmbeddingModel(_CommonReplicate, TextEmbeddingModel):)for input_property in input_properties:- if input_property[0] in ("text", "texts", "inputs"):+ if input_property[0] in {"text", "texts", "inputs"}:text_input_key = input_property[0]return text_input_key@@ -96,7 +96,7 @@ class ReplicateEmbeddingModel(_CommonReplicate, TextEmbeddingModel):def _generate_embeddings_by_text_input_key(client: ReplicateClient, replicate_model_version: str, text_input_key: str, texts: list[str]) -> list[list[float]]:- if text_input_key in ("text", "inputs"):+ if text_input_key in {"text", "inputs"}:embeddings = []for text in texts:result = client.run(replicate_model_version, input={text_input_key: text})diff --git a/api/core/model_runtime/model_providers/tongyi/llm/llm.py b/api/core/model_runtime/model_providers/tongyi/llm/llm.pyindex cd7718361ff..1d4eba6668c 100644--- a/api/core/model_runtime/model_providers/tongyi/llm/llm.py+++ b/api/core/model_runtime/model_providers/tongyi/llm/llm.py@@ -89,7 +89,7 @@ class TongyiLargeLanguageModel(LargeLanguageModel)::param tools: tools for tool calling:return:"""- if model in ["qwen-turbo-chat", "qwen-plus-chat"]:+ if model in {"qwen-turbo-chat", "qwen-plus-chat"}:model = model.replace("-chat", "")if model == "farui-plus":model = "qwen-farui-plus"@@ -157,7 +157,7 @@ class TongyiLargeLanguageModel(LargeLanguageModel):mode = self.get_model_mode(model, credentials)- if model in ["qwen-turbo-chat", "qwen-plus-chat"]:+ if model in {"qwen-turbo-chat", "qwen-plus-chat"}:model = model.replace("-chat", "")extra_model_kwargs = {}@@ -201,7 +201,7 @@ class TongyiLargeLanguageModel(LargeLanguageModel)::param prompt_messages: prompt messages:return: llm response"""- if response.status_code != 200 and response.status_code != HTTPStatus.OK:+ if response.status_code not in {200, HTTPStatus.OK}:raise ServiceUnavailableError(response.message)# transform assistant message to prompt messageassistant_prompt_message = AssistantPromptMessage(@@ -240,7 +240,7 @@ class TongyiLargeLanguageModel(LargeLanguageModel):full_text = ""tool_calls = []for index, response in enumerate(responses):- if response.status_code != 200 and response.status_code != HTTPStatus.OK:+ if response.status_code not in {200, HTTPStatus.OK}:raise ServiceUnavailableError(f"Failed to invoke model {model}, status code: {response.status_code}, "f"message: {response.message}"diff --git a/api/core/model_runtime/model_providers/upstage/llm/llm.py b/api/core/model_runtime/model_providers/upstage/llm/llm.pyindex 74524e81e28..a18ee906248 100644--- a/api/core/model_runtime/model_providers/upstage/llm/llm.py+++ b/api/core/model_runtime/model_providers/upstage/llm/llm.py@@ -93,7 +93,7 @@ class UpstageLargeLanguageModel(_CommonUpstage, LargeLanguageModel):"""Code block mode wrapper for invoking large language model"""- if "response_format" in model_parameters and model_parameters["response_format"] in ["JSON", "XML"]:+ if "response_format" in model_parameters and model_parameters["response_format"] in {"JSON", "XML"}:stop = stop or []self._transform_chat_json_prompts(model=model,diff --git a/api/core/model_runtime/model_providers/vertex_ai/llm/llm.py b/api/core/model_runtime/model_providers/vertex_ai/llm/llm.pyindex dad5002f357..da69b7cdf38 100644--- a/api/core/model_runtime/model_providers/vertex_ai/llm/llm.py+++ b/api/core/model_runtime/model_providers/vertex_ai/llm/llm.py@@ -5,7 +5,6 @@ import loggingfrom collections.abc import Generatorfrom typing import Optional, Union, cast-import google.api_core.exceptions as exceptionsimport google.auth.transport.requestsimport vertexai.generative_models as glmfrom anthropic import AnthropicVertex, Stream@@ -17,6 +16,7 @@ from anthropic.types import (MessageStopEvent,MessageStreamEvent,)+from google.api_core import exceptionsfrom google.cloud import aiplatformfrom google.oauth2 import service_accountfrom PIL import Image@@ -346,7 +346,7 @@ class VertexAiLargeLanguageModel(LargeLanguageModel):mime_type = data_split[0].replace("data:", "")base64_data = data_split[1]- if mime_type not in ["image/jpeg", "image/png", "image/gif", "image/webp"]:+ if mime_type not in {"image/jpeg", "image/png", "image/gif", "image/webp"}:raise ValueError(f"Unsupported image type {mime_type}, "f"only support image/jpeg, image/png, image/gif, and image/webp"diff --git a/api/core/model_runtime/model_providers/volcengine_maas/legacy/volc_sdk/base/auth.py b/api/core/model_runtime/model_providers/volcengine_maas/legacy/volc_sdk/base/auth.pyindex 97c77de8d32..c22bf8e76de 100644--- a/api/core/model_runtime/model_providers/volcengine_maas/legacy/volc_sdk/base/auth.py+++ b/api/core/model_runtime/model_providers/volcengine_maas/legacy/volc_sdk/base/auth.py@@ -96,7 +96,6 @@ class Signer:signing_key = Signer.get_signing_secret_key_v4(credentials.sk, md.date, md.region, md.service)sign = Util.to_hex(Util.hmac_sha256(signing_key, signing_str))request.headers["Authorization"] = Signer.build_auth_header_v4(sign, md, credentials)- return@staticmethoddef hashed_canonical_request_v4(request, meta):@@ -105,7 +104,7 @@ class Signer:signed_headers = {}for key in request.headers:- if key in ["Content-Type", "Content-Md5", "Host"] or key.startswith("X-"):+ if key in {"Content-Type", "Content-Md5", "Host"} or key.startswith("X-"):signed_headers[key.lower()] = request.headers[key]if "host" in signed_headers:diff --git a/api/core/model_runtime/model_providers/wenxin/llm/llm.py b/api/core/model_runtime/model_providers/wenxin/llm/llm.pyindex ec3556f7da8..f7c160b6b47 100644--- a/api/core/model_runtime/model_providers/wenxin/llm/llm.py+++ b/api/core/model_runtime/model_providers/wenxin/llm/llm.py@@ -69,7 +69,7 @@ class ErnieBotLargeLanguageModel(LargeLanguageModel):"""Code block mode wrapper for invoking large language model"""- if "response_format" in model_parameters and model_parameters["response_format"] in ["JSON", "XML"]:+ if "response_format" in model_parameters and model_parameters["response_format"] in {"JSON", "XML"}:response_format = model_parameters["response_format"]stop = stop or []self._transform_json_prompts(diff --git a/api/core/model_runtime/model_providers/xinference/xinference_helper.py b/api/core/model_runtime/model_providers/xinference/xinference_helper.pyindex 1e05da9c56b..619ee1492a9 100644--- a/api/core/model_runtime/model_providers/xinference/xinference_helper.py+++ b/api/core/model_runtime/model_providers/xinference/xinference_helper.py@@ -103,7 +103,7 @@ class XinferenceHelper:model_handle_type = "embedding"elif response_json.get("model_type") == "audio":model_handle_type = "audio"- if model_family and model_family in ["ChatTTS", "CosyVoice", "FishAudio"]:+ if model_family and model_family in {"ChatTTS", "CosyVoice", "FishAudio"}:model_ability.append("text-to-audio")else:model_ability.append("audio-to-text")diff --git a/api/core/model_runtime/model_providers/zhipuai/llm/llm.py b/api/core/model_runtime/model_providers/zhipuai/llm/llm.pyindex f76e51fee9e..ea331701abb 100644--- a/api/core/model_runtime/model_providers/zhipuai/llm/llm.py+++ b/api/core/model_runtime/model_providers/zhipuai/llm/llm.py@@ -186,10 +186,10 @@ class ZhipuAILargeLanguageModel(_CommonZhipuaiAI, LargeLanguageModel):new_prompt_messages: list[PromptMessage] = []for prompt_message in prompt_messages:copy_prompt_message = prompt_message.copy()- if copy_prompt_message.role in [PromptMessageRole.USER, PromptMessageRole.SYSTEM, PromptMessageRole.TOOL]:+ if copy_prompt_message.role in {PromptMessageRole.USER, PromptMessageRole.SYSTEM, PromptMessageRole.TOOL}:if isinstance(copy_prompt_message.content, list):# check if model is 'glm-4v'- if model not in ("glm-4v", "glm-4v-plus"):+ if model not in {"glm-4v", "glm-4v-plus"}:# not support list messagecontinue# get image and@@ -209,10 +209,7 @@ class ZhipuAILargeLanguageModel(_CommonZhipuaiAI, LargeLanguageModel):):new_prompt_messages[-1].content += "\n\n" + copy_prompt_message.contentelse:- if (- copy_prompt_message.role == PromptMessageRole.USER- or copy_prompt_message.role == PromptMessageRole.TOOL- ):+ if copy_prompt_message.role in {PromptMessageRole.USER, PromptMessageRole.TOOL}:new_prompt_messages.append(copy_prompt_message)elif copy_prompt_message.role == PromptMessageRole.SYSTEM:new_prompt_message = SystemPromptMessage(content=copy_prompt_message.content)@@ -226,7 +223,7 @@ class ZhipuAILargeLanguageModel(_CommonZhipuaiAI, LargeLanguageModel):else:new_prompt_messages.append(copy_prompt_message)- if model == "glm-4v" or model == "glm-4v-plus":+ if model in {"glm-4v", "glm-4v-plus"}:params = self._construct_glm_4v_parameter(model, new_prompt_messages, model_parameters)else:params = {"model": model, "messages": [], **model_parameters}@@ -270,11 +267,11 @@ class ZhipuAILargeLanguageModel(_CommonZhipuaiAI, LargeLanguageModel):# chatglm modelfor prompt_message in new_prompt_messages:# merge system message to user message- if (- prompt_message.role == PromptMessageRole.SYSTEM- or prompt_message.role == PromptMessageRole.TOOL- or prompt_message.role == PromptMessageRole.USER- ):+ if prompt_message.role in {+ PromptMessageRole.SYSTEM,+ PromptMessageRole.TOOL,+ PromptMessageRole.USER,+ }:if len(params["messages"]) > 0 and params["messages"][-1]["role"] == "user":params["messages"][-1]["content"] += "\n\n" + prompt_message.contentelse:diff --git a/api/core/model_runtime/model_providers/zhipuai/zhipuai_sdk/types/fine_tuning/__init__.py b/api/core/model_runtime/model_providers/zhipuai/zhipuai_sdk/types/fine_tuning/__init__.pyindex af0991892e0..416f516ef7b 100644--- a/api/core/model_runtime/model_providers/zhipuai/zhipuai_sdk/types/fine_tuning/__init__.py+++ b/api/core/model_runtime/model_providers/zhipuai/zhipuai_sdk/types/fine_tuning/__init__.py@@ -1,5 +1,4 @@from __future__ import annotations-from .fine_tuning_job import FineTuningJob as FineTuningJob-from .fine_tuning_job import ListOfFineTuningJob as ListOfFineTuningJob-from .fine_tuning_job_event import FineTuningJobEvent as FineTuningJobEvent+from .fine_tuning_job import FineTuningJob, ListOfFineTuningJob+from .fine_tuning_job_event import FineTuningJobEventdiff --git a/api/core/model_runtime/schema_validators/common_validator.py b/api/core/model_runtime/schema_validators/common_validator.pyindex c05edb72e35..029ec1a581b 100644--- a/api/core/model_runtime/schema_validators/common_validator.py+++ b/api/core/model_runtime/schema_validators/common_validator.py@@ -75,7 +75,7 @@ class CommonValidator:if not isinstance(value, str):raise ValueError(f"Variable {credential_form_schema.variable} should be string")- if credential_form_schema.type in [FormType.SELECT, FormType.RADIO]:+ if credential_form_schema.type in {FormType.SELECT, FormType.RADIO}:# If the value is in options, no validation is performedif credential_form_schema.options:if value not in [option.value for option in credential_form_schema.options]:@@ -83,7 +83,7 @@ class CommonValidator:if credential_form_schema.type == FormType.SWITCH:# If the value is not in ['true', 'false'], an exception is thrown- if value.lower() not in ["true", "false"]:+ if value.lower() not in {"true", "false"}:raise ValueError(f"Variable {credential_form_schema.variable} should be true or false")value = True if value.lower() == "true" else Falsediff --git a/api/core/rag/datasource/vdb/elasticsearch/elasticsearch_vector.py b/api/core/rag/datasource/vdb/elasticsearch/elasticsearch_vector.pyindex f8300cc2715..8d578551209 100644--- a/api/core/rag/datasource/vdb/elasticsearch/elasticsearch_vector.py+++ b/api/core/rag/datasource/vdb/elasticsearch/elasticsearch_vector.py@@ -51,7 +51,7 @@ class ElasticSearchVector(BaseVector):def _init_client(self, config: ElasticSearchConfig) -> Elasticsearch:try:parsed_url = urlparse(config.host)- if parsed_url.scheme in ["http", "https"]:+ if parsed_url.scheme in {"http", "https"}:hosts = f"{config.host}:{config.port}"else:hosts = f"http://{config.host}:{config.port}"@@ -94,7 +94,7 @@ class ElasticSearchVector(BaseVector):return uuidsdef text_exists(self, id: str) -> bool:- return self._client.exists(index=self._collection_name, id=id).__bool__()+ return bool(self._client.exists(index=self._collection_name, id=id))def delete_by_ids(self, ids: list[str]) -> None:for id in ids:diff --git a/api/core/rag/datasource/vdb/myscale/myscale_vector.py b/api/core/rag/datasource/vdb/myscale/myscale_vector.pyindex 1bd5bcd3e45..2320a69a30a 100644--- a/api/core/rag/datasource/vdb/myscale/myscale_vector.py+++ b/api/core/rag/datasource/vdb/myscale/myscale_vector.py@@ -35,7 +35,7 @@ class MyScaleVector(BaseVector):super().__init__(collection_name)self._config = configself._metric = metric- self._vec_order = SortOrder.ASC if metric.upper() in ["COSINE", "L2"] else SortOrder.DESC+ self._vec_order = SortOrder.ASC if metric.upper() in {"COSINE", "L2"} else SortOrder.DESCself._client = get_client(host=config.host,port=config.port,@@ -92,7 +92,7 @@ class MyScaleVector(BaseVector):@staticmethoddef escape_str(value: Any) -> str:- return "".join(" " if c in ("\\", "'") else c for c in str(value))+ return "".join(" " if c in {"\\", "'"} else c for c in str(value))def text_exists(self, id: str) -> bool:results = self._client.query(f"SELECT id FROM {self._config.database}.{self._collection_name} WHERE id='{id}'")diff --git a/api/core/rag/datasource/vdb/oracle/oraclevector.py b/api/core/rag/datasource/vdb/oracle/oraclevector.pyindex b974fa80a4a..77ec45b4d39 100644--- a/api/core/rag/datasource/vdb/oracle/oraclevector.py+++ b/api/core/rag/datasource/vdb/oracle/oraclevector.py@@ -223,15 +223,7 @@ class OracleVector(BaseVector):words = pseg.cut(query)current_entity = ""for word, pos in words:- if (- pos == "nr"- or pos == "Ng"- or pos == "eng"- or pos == "nz"- or pos == "n"- or pos == "ORG"- or pos == "v"- ): # nr: 人名, ns: 地名, nt: 机构名+ if pos in {"nr", "Ng", "eng", "nz", "n", "ORG", "v"}: # nr: 人名, ns: 地名, nt: 机构名current_entity += wordelse:if current_entity:diff --git a/api/core/rag/extractor/extract_processor.py b/api/core/rag/extractor/extract_processor.pyindex 3181656f592..fe7eaa32e62 100644--- a/api/core/rag/extractor/extract_processor.py+++ b/api/core/rag/extractor/extract_processor.py@@ -98,17 +98,17 @@ class ExtractProcessor:unstructured_api_url = dify_config.UNSTRUCTURED_API_URLunstructured_api_key = dify_config.UNSTRUCTURED_API_KEYif etl_type == "Unstructured":- if file_extension == ".xlsx" or file_extension == ".xls":+ if file_extension in {".xlsx", ".xls"}:extractor = ExcelExtractor(file_path)elif file_extension == ".pdf":extractor = PdfExtractor(file_path)- elif file_extension in [".md", ".markdown"]:+ elif file_extension in {".md", ".markdown"}:extractor = (UnstructuredMarkdownExtractor(file_path, unstructured_api_url)if is_automaticelse MarkdownExtractor(file_path, autodetect_encoding=True))- elif file_extension in [".htm", ".html"]:+ elif file_extension in {".htm", ".html"}:extractor = HtmlExtractor(file_path)elif file_extension == ".docx":extractor = WordExtractor(file_path, upload_file.tenant_id, upload_file.created_by)@@ -134,13 +134,13 @@ class ExtractProcessor:else TextExtractor(file_path, autodetect_encoding=True))else:- if file_extension == ".xlsx" or file_extension == ".xls":+ if file_extension in {".xlsx", ".xls"}:extractor = ExcelExtractor(file_path)elif file_extension == ".pdf":extractor = PdfExtractor(file_path)- elif file_extension in [".md", ".markdown"]:+ elif file_extension in {".md", ".markdown"}:extractor = MarkdownExtractor(file_path, autodetect_encoding=True)- elif file_extension in [".htm", ".html"]:+ elif file_extension in {".htm", ".html"}:extractor = HtmlExtractor(file_path)elif file_extension == ".docx":extractor = WordExtractor(file_path, upload_file.tenant_id, upload_file.created_by)diff --git a/api/core/rag/extractor/firecrawl/firecrawl_app.py b/api/core/rag/extractor/firecrawl/firecrawl_app.pyindex 054ce5f4b2e..17c2087a0ab 100644--- a/api/core/rag/extractor/firecrawl/firecrawl_app.py+++ b/api/core/rag/extractor/firecrawl/firecrawl_app.py@@ -32,7 +32,7 @@ class FirecrawlApp:else:raise Exception(f'Failed to scrape URL. Error: {response["error"]}')- elif response.status_code in [402, 409, 500]:+ elif response.status_code in {402, 409, 500}:error_message = response.json().get("error", "Unknown error occurred")raise Exception(f"Failed to scrape URL. Status code: {response.status_code}. Error: {error_message}")else:diff --git a/api/core/rag/extractor/notion_extractor.py b/api/core/rag/extractor/notion_extractor.pyindex 0ee24983a42..87a4ce08bf3 100644--- a/api/core/rag/extractor/notion_extractor.py+++ b/api/core/rag/extractor/notion_extractor.py@@ -103,12 +103,12 @@ class NotionExtractor(BaseExtractor):multi_select_list = property_value[type]for multi_select in multi_select_list:value.append(multi_select["name"])- elif type == "rich_text" or type == "title":+ elif type in {"rich_text", "title"}:if len(property_value[type]) > 0:value = property_value[type][0]["plain_text"]else:value = ""- elif type == "select" or type == "status":+ elif type in {"select", "status"}:if property_value[type]:value = property_value[type]["name"]else:diff --git a/api/core/rag/retrieval/dataset_retrieval.py b/api/core/rag/retrieval/dataset_retrieval.pyindex 12868d6ae43..124c58f0fe2 100644--- a/api/core/rag/retrieval/dataset_retrieval.py+++ b/api/core/rag/retrieval/dataset_retrieval.py@@ -115,7 +115,7 @@ class DatasetRetrieval:available_datasets.append(dataset)all_documents = []- user_from = "account" if invoke_from in [InvokeFrom.EXPLORE, InvokeFrom.DEBUGGER] else "end_user"+ user_from = "account" if invoke_from in {InvokeFrom.EXPLORE, InvokeFrom.DEBUGGER} else "end_user"if retrieve_config.retrieve_strategy == DatasetRetrieveConfigEntity.RetrieveStrategy.SINGLE:all_documents = self.single_retrieve(app_id,diff --git a/api/core/rag/splitter/text_splitter.py b/api/core/rag/splitter/text_splitter.pyindex 161c36607da..7dd62f8de18 100644--- a/api/core/rag/splitter/text_splitter.py+++ b/api/core/rag/splitter/text_splitter.py@@ -35,7 +35,7 @@ def _split_text_with_regex(text: str, separator: str, keep_separator: bool) -> lsplits = re.split(separator, text)else:splits = list(text)- return [s for s in splits if (s != "" and s != "\n")]+ return [s for s in splits if (s not in {"", "\n"})]class TextSplitter(BaseDocumentTransformer, ABC):diff --git a/api/core/tools/provider/app_tool_provider.py b/api/core/tools/provider/app_tool_provider.pyindex 01544d7e562..09f328cd1fe 100644--- a/api/core/tools/provider/app_tool_provider.py+++ b/api/core/tools/provider/app_tool_provider.py@@ -68,7 +68,7 @@ class AppToolProviderEntity(ToolProviderController):label = input_form[form_type]["label"]variable_name = input_form[form_type]["variable_name"]options = input_form[form_type].get("options", [])- if form_type == "paragraph" or form_type == "text-input":+ if form_type in {"paragraph", "text-input"}:tool["parameters"].append(ToolParameter(name=variable_name,diff --git a/api/core/tools/provider/builtin/aippt/tools/aippt.py b/api/core/tools/provider/builtin/aippt/tools/aippt.pyindex a2d69fbcd1a..dd9371f70d6 100644--- a/api/core/tools/provider/builtin/aippt/tools/aippt.py+++ b/api/core/tools/provider/builtin/aippt/tools/aippt.py@@ -168,7 +168,7 @@ class AIPPTGenerateTool(BuiltinTool):passelif event == "close":break- elif event == "error" or event == "filter":+ elif event in {"error", "filter"}:raise Exception(f"Failed to generate outline: {data}")return outline@@ -213,7 +213,7 @@ class AIPPTGenerateTool(BuiltinTool):passelif event == "close":break- elif event == "error" or event == "filter":+ elif event in {"error", "filter"}:raise Exception(f"Failed to generate content: {data}")return contentdiff --git a/api/core/tools/provider/builtin/azuredalle/tools/dalle3.py b/api/core/tools/provider/builtin/azuredalle/tools/dalle3.pyindex 7462824be1e..cfa3cfb0928 100644--- a/api/core/tools/provider/builtin/azuredalle/tools/dalle3.py+++ b/api/core/tools/provider/builtin/azuredalle/tools/dalle3.py@@ -39,11 +39,11 @@ class DallE3Tool(BuiltinTool):n = tool_parameters.get("n", 1)# get qualityquality = tool_parameters.get("quality", "standard")- if quality not in ["standard", "hd"]:+ if quality not in {"standard", "hd"}:return self.create_text_message("Invalid quality")# get stylestyle = tool_parameters.get("style", "vivid")- if style not in ["natural", "vivid"]:+ if style not in {"natural", "vivid"}:return self.create_text_message("Invalid style")# set extra bodyseed_id = tool_parameters.get("seed_id", self._generate_random_id(8))diff --git a/api/core/tools/provider/builtin/code/tools/simple_code.py b/api/core/tools/provider/builtin/code/tools/simple_code.pyindex 017fe548f76..632c9fc7f14 100644--- a/api/core/tools/provider/builtin/code/tools/simple_code.py+++ b/api/core/tools/provider/builtin/code/tools/simple_code.py@@ -14,7 +14,7 @@ class SimpleCode(BuiltinTool):language = tool_parameters.get("language", CodeLanguage.PYTHON3)code = tool_parameters.get("code", "")- if language not in [CodeLanguage.PYTHON3, CodeLanguage.JAVASCRIPT]:+ if language not in {CodeLanguage.PYTHON3, CodeLanguage.JAVASCRIPT}:raise ValueError(f"Only python3 and javascript are supported, not {language}")result = CodeExecutor.execute_code(language, "", code)diff --git a/api/core/tools/provider/builtin/cogview/tools/cogview3.py b/api/core/tools/provider/builtin/cogview/tools/cogview3.pyindex 9776bd7dd1c..9039708588d 100644--- a/api/core/tools/provider/builtin/cogview/tools/cogview3.py+++ b/api/core/tools/provider/builtin/cogview/tools/cogview3.py@@ -34,11 +34,11 @@ class CogView3Tool(BuiltinTool):n = tool_parameters.get("n", 1)# get qualityquality = tool_parameters.get("quality", "standard")- if quality not in ["standard", "hd"]:+ if quality not in {"standard", "hd"}:return self.create_text_message("Invalid quality")# get stylestyle = tool_parameters.get("style", "vivid")- if style not in ["natural", "vivid"]:+ if style not in {"natural", "vivid"}:return self.create_text_message("Invalid style")# set extra bodyseed_id = tool_parameters.get("seed_id", self._generate_random_id(8))diff --git a/api/core/tools/provider/builtin/dalle/tools/dalle3.py b/api/core/tools/provider/builtin/dalle/tools/dalle3.pyindex bcfa2212b6c..a8c647d71e6 100644--- a/api/core/tools/provider/builtin/dalle/tools/dalle3.py+++ b/api/core/tools/provider/builtin/dalle/tools/dalle3.py@@ -49,11 +49,11 @@ class DallE3Tool(BuiltinTool):n = tool_parameters.get("n", 1)# get qualityquality = tool_parameters.get("quality", "standard")- if quality not in ["standard", "hd"]:+ if quality not in {"standard", "hd"}:return self.create_text_message("Invalid quality")# get stylestyle = tool_parameters.get("style", "vivid")- if style not in ["natural", "vivid"]:+ if style not in {"natural", "vivid"}:return self.create_text_message("Invalid style")# call openapi dalle3diff --git a/api/core/tools/provider/builtin/hap/tools/get_worksheet_fields.py b/api/core/tools/provider/builtin/hap/tools/get_worksheet_fields.pyindex 40e1af043b3..79e5889eaef 100644--- a/api/core/tools/provider/builtin/hap/tools/get_worksheet_fields.py+++ b/api/core/tools/provider/builtin/hap/tools/get_worksheet_fields.py@@ -133,9 +133,9 @@ class GetWorksheetFieldsTool(BuiltinTool):def _extract_options(self, control: dict) -> list:options = []- if control["type"] in [9, 10, 11]:+ if control["type"] in {9, 10, 11}:options.extend([{"key": opt["key"], "value": opt["value"]} for opt in control.get("options", [])])- elif control["type"] in [28, 36]:+ elif control["type"] in {28, 36}:itemnames = control["advancedSetting"].get("itemnames")if itemnames and itemnames.startswith("[{"):try:diff --git a/api/core/tools/provider/builtin/hap/tools/list_worksheet_records.py b/api/core/tools/provider/builtin/hap/tools/list_worksheet_records.pyindex 171895a3060..44c7e523070 100644--- a/api/core/tools/provider/builtin/hap/tools/list_worksheet_records.py+++ b/api/core/tools/provider/builtin/hap/tools/list_worksheet_records.py@@ -183,11 +183,11 @@ class ListWorksheetRecordsTool(BuiltinTool):type_id = field.get("typeId")if type_id == 10:value = value if isinstance(value, str) else "、".join(value)- elif type_id in [28, 36]:+ elif type_id in {28, 36}:value = field.get("options", {}).get(value, value)- elif type_id in [26, 27, 48, 14]:+ elif type_id in {26, 27, 48, 14}:value = self.process_value(value)- elif type_id in [35, 29]:+ elif type_id in {35, 29}:value = self.parse_cascade_or_associated(field, value)elif type_id == 40:value = self.parse_location(value)diff --git a/api/core/tools/provider/builtin/novitaai/tools/novitaai_modelquery.py b/api/core/tools/provider/builtin/novitaai/tools/novitaai_modelquery.pyindex 9ca14b327ca..a200ee81231 100644--- a/api/core/tools/provider/builtin/novitaai/tools/novitaai_modelquery.py+++ b/api/core/tools/provider/builtin/novitaai/tools/novitaai_modelquery.py@@ -35,7 +35,7 @@ class NovitaAiModelQueryTool(BuiltinTool):models_data=[],headers=headers,params=params,- recursive=not (result_type == "first sd_name" or result_type == "first name sd_name pair"),+ recursive=result_type not in {"first sd_name", "first name sd_name pair"},)result_str = ""diff --git a/api/core/tools/provider/builtin/searchapi/tools/google.py b/api/core/tools/provider/builtin/searchapi/tools/google.pyindex 16ae14549d2..17e2978194c 100644--- a/api/core/tools/provider/builtin/searchapi/tools/google.py+++ b/api/core/tools/provider/builtin/searchapi/tools/google.py@@ -38,7 +38,7 @@ class SearchAPI:return {"engine": "google","q": query,- **{key: value for key, value in kwargs.items() if value not in [None, ""]},+ **{key: value for key, value in kwargs.items() if value not in {None, ""}},}@staticmethoddiff --git a/api/core/tools/provider/builtin/searchapi/tools/google_jobs.py b/api/core/tools/provider/builtin/searchapi/tools/google_jobs.pyindex d29cb0ae3f1..c478bc108b4 100644--- a/api/core/tools/provider/builtin/searchapi/tools/google_jobs.py+++ b/api/core/tools/provider/builtin/searchapi/tools/google_jobs.py@@ -38,7 +38,7 @@ class SearchAPI:return {"engine": "google_jobs","q": query,- **{key: value for key, value in kwargs.items() if value not in [None, ""]},+ **{key: value for key, value in kwargs.items() if value not in {None, ""}},}@staticmethoddiff --git a/api/core/tools/provider/builtin/searchapi/tools/google_news.py b/api/core/tools/provider/builtin/searchapi/tools/google_news.pyindex 8458c8c958e..562bc01964b 100644--- a/api/core/tools/provider/builtin/searchapi/tools/google_news.py+++ b/api/core/tools/provider/builtin/searchapi/tools/google_news.py@@ -38,7 +38,7 @@ class SearchAPI:return {"engine": "google_news","q": query,- **{key: value for key, value in kwargs.items() if value not in [None, ""]},+ **{key: value for key, value in kwargs.items() if value not in {None, ""}},}@staticmethoddiff --git a/api/core/tools/provider/builtin/searchapi/tools/youtube_transcripts.py b/api/core/tools/provider/builtin/searchapi/tools/youtube_transcripts.pyindex 09725cf8a2a..1867cf7be79 100644--- a/api/core/tools/provider/builtin/searchapi/tools/youtube_transcripts.py+++ b/api/core/tools/provider/builtin/searchapi/tools/youtube_transcripts.py@@ -38,7 +38,7 @@ class SearchAPI:"engine": "youtube_transcripts","video_id": video_id,"lang": language or "en",- **{key: value for key, value in kwargs.items() if value not in [None, ""]},+ **{key: value for key, value in kwargs.items() if value not in {None, ""}},}@staticmethoddiff --git a/api/core/tools/provider/builtin/spider/spiderApp.py b/api/core/tools/provider/builtin/spider/spiderApp.pyindex 3972e560c41..4bc446a1a09 100644--- a/api/core/tools/provider/builtin/spider/spiderApp.py+++ b/api/core/tools/provider/builtin/spider/spiderApp.py@@ -214,7 +214,7 @@ class Spider:return requests.delete(url, headers=headers, stream=stream)def _handle_error(self, response, action):- if response.status_code in [402, 409, 500]:+ if response.status_code in {402, 409, 500}:error_message = response.json().get("error", "Unknown error occurred")raise Exception(f"Failed to {action}. Status code: {response.status_code}. Error: {error_message}")else:diff --git a/api/core/tools/provider/builtin/stability/tools/text2image.py b/api/core/tools/provider/builtin/stability/tools/text2image.pyindex 9f415ceb550..6bcf315484a 100644--- a/api/core/tools/provider/builtin/stability/tools/text2image.py+++ b/api/core/tools/provider/builtin/stability/tools/text2image.py@@ -32,7 +32,7 @@ class StableDiffusionTool(BuiltinTool, BaseStabilityAuthorization):model = tool_parameters.get("model", "core")- if model in ["sd3", "sd3-turbo"]:+ if model in {"sd3", "sd3-turbo"}:payload["model"] = tool_parameters.get("model")if model != "sd3-turbo":diff --git a/api/core/tools/provider/builtin/vanna/tools/vanna.py b/api/core/tools/provider/builtin/vanna/tools/vanna.pyindex a6efb0f79a5..c90d766e483 100644--- a/api/core/tools/provider/builtin/vanna/tools/vanna.py+++ b/api/core/tools/provider/builtin/vanna/tools/vanna.py@@ -38,7 +38,7 @@ class VannaTool(BuiltinTool):vn = VannaDefault(model=model, api_key=api_key)db_type = tool_parameters.get("db_type", "")- if db_type in ["Postgres", "MySQL", "Hive", "ClickHouse"]:+ if db_type in {"Postgres", "MySQL", "Hive", "ClickHouse"}:if not db_name:return self.create_text_message("Please input database name")if not username:diff --git a/api/core/tools/provider/builtin_tool_provider.py b/api/core/tools/provider/builtin_tool_provider.pyindex 6b64dd1b4e3..ff022812ef5 100644--- a/api/core/tools/provider/builtin_tool_provider.py+++ b/api/core/tools/provider/builtin_tool_provider.py@@ -19,7 +19,7 @@ from core.tools.utils.yaml_utils import load_yaml_fileclass BuiltinToolProviderController(ToolProviderController):def __init__(self, **data: Any) -> None:- if self.provider_type == ToolProviderType.API or self.provider_type == ToolProviderType.APP:+ if self.provider_type in {ToolProviderType.API, ToolProviderType.APP}:super().__init__(**data)returndiff --git a/api/core/tools/provider/tool_provider.py b/api/core/tools/provider/tool_provider.pyindex f4008eedce8..7ba9dda1799 100644--- a/api/core/tools/provider/tool_provider.py+++ b/api/core/tools/provider/tool_provider.py@@ -153,10 +153,10 @@ class ToolProviderController(BaseModel, ABC):# check typecredential_schema = credentials_need_to_validate[credential_name]- if (- credential_schema == ToolProviderCredentials.CredentialsType.SECRET_INPUT- or credential_schema == ToolProviderCredentials.CredentialsType.TEXT_INPUT- ):+ if credential_schema in {+ ToolProviderCredentials.CredentialsType.SECRET_INPUT,+ ToolProviderCredentials.CredentialsType.TEXT_INPUT,+ }:if not isinstance(credentials[credential_name], str):raise ToolProviderCredentialValidationError(f"credential {credential_name} should be string")@@ -184,11 +184,11 @@ class ToolProviderController(BaseModel, ABC):if credential_schema.default is not None:default_value = credential_schema.default# parse default value into the correct type- if (- credential_schema.type == ToolProviderCredentials.CredentialsType.SECRET_INPUT- or credential_schema.type == ToolProviderCredentials.CredentialsType.TEXT_INPUT- or credential_schema.type == ToolProviderCredentials.CredentialsType.SELECT- ):+ if credential_schema.type in {+ ToolProviderCredentials.CredentialsType.SECRET_INPUT,+ ToolProviderCredentials.CredentialsType.TEXT_INPUT,+ ToolProviderCredentials.CredentialsType.SELECT,+ }:default_value = str(default_value)credentials[credential_name] = default_valuediff --git a/api/core/tools/tool/api_tool.py b/api/core/tools/tool/api_tool.pyindex bf336b48f30..c779d704c36 100644--- a/api/core/tools/tool/api_tool.py+++ b/api/core/tools/tool/api_tool.py@@ -5,7 +5,7 @@ from urllib.parse import urlencodeimport httpx-import core.helper.ssrf_proxy as ssrf_proxy+from core.helper import ssrf_proxyfrom core.tools.entities.tool_bundle import ApiToolBundlefrom core.tools.entities.tool_entities import ToolInvokeMessage, ToolProviderTypefrom core.tools.errors import ToolInvokeError, ToolParameterValidationError, ToolProviderCredentialValidationError@@ -191,7 +191,7 @@ class ApiTool(Tool):else:body = body- if method in ("get", "head", "post", "put", "delete", "patch"):+ if method in {"get", "head", "post", "put", "delete", "patch"}:response = getattr(ssrf_proxy, method)(url,params=params,@@ -224,9 +224,9 @@ class ApiTool(Tool):elif option["type"] == "string":return str(value)elif option["type"] == "boolean":- if str(value).lower() in ["true", "1"]:+ if str(value).lower() in {"true", "1"}:return True- elif str(value).lower() in ["false", "0"]:+ elif str(value).lower() in {"false", "0"}:return Falseelse:continue # Not a boolean, try next optiondiff --git a/api/core/tools/tool_engine.py b/api/core/tools/tool_engine.pyindex 645f0861fa0..9912114dd6a 100644--- a/api/core/tools/tool_engine.py+++ b/api/core/tools/tool_engine.py@@ -189,10 +189,7 @@ class ToolEngine:result += response.messageelif response.type == ToolInvokeMessage.MessageType.LINK:result += f"result link: {response.message}. please tell user to check it."- elif (- response.type == ToolInvokeMessage.MessageType.IMAGE_LINK- or response.type == ToolInvokeMessage.MessageType.IMAGE- ):+ elif response.type in {ToolInvokeMessage.MessageType.IMAGE_LINK, ToolInvokeMessage.MessageType.IMAGE}:result += ("image has been created and sent to user already, you do not need to create it,"" just tell the user to check it now."@@ -212,10 +209,7 @@ class ToolEngine: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}:mimetype = Noneif response.meta.get("mime_type"):mimetype = response.meta.get("mime_type")@@ -297,7 +291,7 @@ class ToolEngine:belongs_to="assistant",url=message.url,upload_file_id=None,- created_by_role=("account" if invoke_from in [InvokeFrom.EXPLORE, InvokeFrom.DEBUGGER] else "end_user"),+ created_by_role=("account" if invoke_from in {InvokeFrom.EXPLORE, InvokeFrom.DEBUGGER} else "end_user"),created_by=user_id,)diff --git a/api/core/tools/utils/message_transformer.py b/api/core/tools/utils/message_transformer.pyindex bf040d91d39..3cfab207ba7 100644--- a/api/core/tools/utils/message_transformer.py+++ b/api/core/tools/utils/message_transformer.py@@ -19,7 +19,7 @@ class ToolFileMessageTransformer:result = []for message in messages:- if message.type == ToolInvokeMessage.MessageType.TEXT or message.type == ToolInvokeMessage.MessageType.LINK:+ if message.type in {ToolInvokeMessage.MessageType.TEXT, ToolInvokeMessage.MessageType.LINK}:result.append(message)elif message.type == ToolInvokeMessage.MessageType.IMAGE:# try to download imagediff --git a/api/core/tools/utils/parser.py b/api/core/tools/utils/parser.pyindex 210b84b29a7..9ead4f8e5cf 100644--- a/api/core/tools/utils/parser.py+++ b/api/core/tools/utils/parser.py@@ -165,7 +165,7 @@ class ApiBasedToolSchemaParser:elif "schema" in parameter and "type" in parameter["schema"]:typ = parameter["schema"]["type"]- if typ == "integer" or typ == "number":+ if typ in {"integer", "number"}:return ToolParameter.ToolParameterType.NUMBERelif typ == "boolean":return ToolParameter.ToolParameterType.BOOLEANdiff --git a/api/core/tools/utils/web_reader_tool.py b/api/core/tools/utils/web_reader_tool.pyindex e57cae9f16a..1ced7d0488e 100644--- a/api/core/tools/utils/web_reader_tool.py+++ b/api/core/tools/utils/web_reader_tool.py@@ -313,7 +313,7 @@ def normalize_whitespace(text):def is_leaf(element):- return element.name in ["p", "li"]+ return element.name in {"p", "li"}def is_text(element):diff --git a/api/core/workflow/graph_engine/entities/runtime_route_state.py b/api/core/workflow/graph_engine/entities/runtime_route_state.pyindex 8fc80474265..bb24b511127 100644--- a/api/core/workflow/graph_engine/entities/runtime_route_state.py+++ b/api/core/workflow/graph_engine/entities/runtime_route_state.py@@ -51,7 +51,7 @@ class RouteNodeState(BaseModel)::param run_result: run result"""- if self.status in [RouteNodeState.Status.SUCCESS, RouteNodeState.Status.FAILED]:+ if self.status in {RouteNodeState.Status.SUCCESS, RouteNodeState.Status.FAILED}:raise Exception(f"Route state {self.id} already finished")if run_result.status == WorkflowNodeExecutionStatus.SUCCEEDED:diff --git a/api/core/workflow/nodes/answer/answer_stream_generate_router.py b/api/core/workflow/nodes/answer/answer_stream_generate_router.pyindex e31a1479a8f..5e6de8fb153 100644--- a/api/core/workflow/nodes/answer/answer_stream_generate_router.py+++ b/api/core/workflow/nodes/answer/answer_stream_generate_router.py@@ -148,11 +148,11 @@ class AnswerStreamGeneratorRouter:for edge in reverse_edges:source_node_id = edge.source_node_idsource_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(diff --git a/api/core/workflow/nodes/end/end_stream_generate_router.py b/api/core/workflow/nodes/end/end_stream_generate_router.pyindex a38d9823938..9a7d2ecde3b 100644--- a/api/core/workflow/nodes/end/end_stream_generate_router.py+++ b/api/core/workflow/nodes/end/end_stream_generate_router.py@@ -136,10 +136,10 @@ class EndStreamGeneratorRouter:for edge in reverse_edges:source_node_id = edge.source_node_idsource_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(diff --git a/api/core/workflow/nodes/http_request/http_executor.py b/api/core/workflow/nodes/http_request/http_executor.pyindex 49102dc3ab1..f8ab4e31324 100644--- a/api/core/workflow/nodes/http_request/http_executor.py+++ b/api/core/workflow/nodes/http_request/http_executor.py@@ -6,8 +6,8 @@ from urllib.parse import urlencodeimport httpx-import core.helper.ssrf_proxy as ssrf_proxyfrom configs import dify_config+from core.helper import ssrf_proxyfrom core.workflow.entities.variable_entities import VariableSelectorfrom core.workflow.entities.variable_pool import VariablePoolfrom 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_dataelif 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}")diff --git a/api/core/workflow/nodes/parameter_extractor/entities.py b/api/core/workflow/nodes/parameter_extractor/entities.pyindex 802ed31e27a..5697d7c0498 100644--- a/api/core/workflow/nodes/parameter_extractor/entities.py+++ b/api/core/workflow/nodes/parameter_extractor/entities.py@@ -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"diff --git a/api/core/workflow/nodes/parameter_extractor/parameter_extractor_node.py b/api/core/workflow/nodes/parameter_extractor/parameter_extractor_node.pyindex 131d26b19ea..a6454bd1cd2 100644--- a/api/core/workflow/nodes/parameter_extractor/parameter_extractor_node.py+++ b/api/core/workflow/nodes/parameter_extractor/parameter_extractor_node.py@@ -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] = 0elif 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 emptyif not stack:return text[:i]@@ -560,7 +560,7 @@ class ParameterExtractorNode(LLMNode):result[parameter.name] = 0elif parameter.type == "bool":result[parameter.name] = False- elif parameter.type in ["string", "select"]:+ elif parameter.type in {"string", "select"}:result[parameter.name] = ""return resultdiff --git a/api/core/workflow/nodes/tool/tool_node.py b/api/core/workflow/nodes/tool/tool_node.pyindex e55adfc1f40..3b86b29cf8e 100644--- a/api/core/workflow/nodes/tool/tool_node.py+++ b/api/core/workflow/nodes/tool/tool_node.py@@ -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.messageext = path.splitext(url)[1]mimetype = response.meta.get("mime_type", "image/jpeg")diff --git a/api/libs/oauth_data_source.py b/api/libs/oauth_data_source.pyindex 6da1a6d39bf..05a73b09b7b 100644--- a/api/libs/oauth_data_source.py+++ b/api/libs/oauth_data_source.py@@ -158,7 +158,7 @@ class NotionOAuth(OAuthDataSource):page_icon = page_result["icon"]if page_icon:icon_type = page_icon["type"]- if icon_type == "external" or icon_type == "file":+ if icon_type in {"external", "file"}:url = page_icon[icon_type]["url"]icon = {"type": "url", "url": url if url.startswith("http") else f"https://www.notion.so{url}"}else:@@ -191,7 +191,7 @@ class NotionOAuth(OAuthDataSource):page_icon = database_result["icon"]if page_icon:icon_type = page_icon["type"]- if icon_type == "external" or icon_type == "file":+ if icon_type in {"external", "file"}:url = page_icon[icon_type]["url"]icon = {"type": "url", "url": url if url.startswith("http") else f"https://www.notion.so{url}"}else:diff --git a/api/libs/rsa.py b/api/libs/rsa.pyindex a578bf3e561..637bcc4a1dd 100644--- a/api/libs/rsa.py+++ b/api/libs/rsa.py@@ -4,9 +4,9 @@ from Crypto.Cipher import AESfrom Crypto.PublicKey import RSAfrom Crypto.Random import get_random_bytes-import libs.gmpy2_pkcs10aep_cipher as gmpy2_pkcs10aep_cipherfrom extensions.ext_redis import redis_clientfrom extensions.ext_storage import storage+from libs import gmpy2_pkcs10aep_cipherdef generate_key_pair(tenant_id):diff --git a/api/models/dataset.py b/api/models/dataset.pyindex 0da35910cd4..a2d2a3454d4 100644--- a/api/models/dataset.py+++ b/api/models/dataset.py@@ -284,9 +284,9 @@ class Document(db.Model):status = Noneif self.indexing_status == "waiting":status = "queuing"- elif self.indexing_status not in ["completed", "error", "waiting"] and self.is_paused:+ elif self.indexing_status not in {"completed", "error", "waiting"} and self.is_paused:status = "paused"- elif self.indexing_status in ["parsing", "cleaning", "splitting", "indexing"]:+ elif self.indexing_status in {"parsing", "cleaning", "splitting", "indexing"}:status = "indexing"elif self.indexing_status == "error":status = "error"@@ -331,7 +331,7 @@ class Document(db.Model):"created_at": file_detail.created_at.timestamp(),}}- elif self.data_source_type == "notion_import" or self.data_source_type == "website_crawl":+ elif self.data_source_type in {"notion_import", "website_crawl"}:return json.loads(self.data_source_info)return {}diff --git a/api/models/model.py b/api/models/model.pyindex a8b2e00ee44..ae0bc3210b6 100644--- a/api/models/model.py+++ b/api/models/model.py@@ -134,7 +134,7 @@ class App(db.Model):return Falseif self.app_model_config.agent_mode_dict.get("enabled", False) and self.app_model_config.agent_mode_dict.get("strategy", ""- ) in ["function_call", "react"]:+ ) in {"function_call", "react"}:self.mode = AppMode.AGENT_CHAT.valuedb.session.commit()return True@@ -1501,6 +1501,6 @@ class TraceAppConfig(db.Model):"tracing_provider": self.tracing_provider,"tracing_config": self.tracing_config_dict,"is_active": self.is_active,- "created_at": self.created_at.__str__() if self.created_at else None,- "updated_at": self.updated_at.__str__() if self.updated_at else None,+ "created_at": str(self.created_at) if self.created_at else None,+ "updated_at": str(self.updated_at) if self.updated_at else None,}diff --git a/api/pyproject.toml b/api/pyproject.tomlindex 83aa35c5429..57a3844200b 100644--- a/api/pyproject.toml+++ b/api/pyproject.toml@@ -6,6 +6,9 @@ requires = ["poetry-core"]build-backend = "poetry.core.masonry.api"[tool.ruff]+exclude=[+ "migrations/*",+]line-length = 120[tool.ruff.lint]@@ -19,6 +22,13 @@ select = ["I", # isort rules"N", # pep8-naming"PT", # flake8-pytest-style rules+ "PLC0208", # iteration-over-set+ "PLC2801", # unnecessary-dunder-call+ "PLC0414", # useless-import-alias+ "PLR0402", # manual-from-import+ "PLR1711", # useless-return+ "PLR1714", # repeated-equality-comparison+ "PLR6201", # literal-membership"RUF019", # unnecessary-key-check"RUF100", # unused-noqa"RUF101", # redirected-noqa@@ -78,9 +88,6 @@ ignore = ["libs/gmpy2_pkcs10aep_cipher.py" = ["N803", # invalid-argument-name]-"migrations/versions/*" = [- "E501", # line-too-long-]"tests/*" = ["F401", # unused-import"F811", # redefined-while-unused@@ -88,7 +95,6 @@ ignore = [[tool.ruff.format]exclude = [- "migrations/**/*",][tool.pytest_env]diff --git a/api/services/account_service.py b/api/services/account_service.pyindex e839ae54bae..66ff5d2b7ce 100644--- a/api/services/account_service.py+++ b/api/services/account_service.py@@ -47,7 +47,7 @@ class AccountService:if not account:return None- if account.status in [AccountStatus.BANNED.value, AccountStatus.CLOSED.value]:+ if account.status in {AccountStatus.BANNED.value, AccountStatus.CLOSED.value}:raise Unauthorized("Account is banned or closed.")current_tenant: TenantAccountJoin = TenantAccountJoin.query.filter_by(@@ -92,7 +92,7 @@ class AccountService:if not account:raise AccountLoginError("Invalid email or password.")- if account.status == AccountStatus.BANNED.value or account.status == AccountStatus.CLOSED.value:+ if account.status in {AccountStatus.BANNED.value, AccountStatus.CLOSED.value}:raise AccountLoginError("Account is banned or closed.")if account.status == AccountStatus.PENDING.value:@@ -427,7 +427,7 @@ class TenantService:"remove": [TenantAccountRole.OWNER],"update": [TenantAccountRole.OWNER],}- if action not in ["add", "remove", "update"]:+ if action not in {"add", "remove", "update"}:raise InvalidActionError("Invalid action.")if member:diff --git a/api/services/app_dsl_service.py b/api/services/app_dsl_service.pyindex 2fe39b52249..54594e1175d 100644--- a/api/services/app_dsl_service.py+++ b/api/services/app_dsl_service.py@@ -90,7 +90,7 @@ class AppDslService:# import dsl and create appapp_mode = AppMode.value_of(app_data.get("mode"))- if app_mode in [AppMode.ADVANCED_CHAT, AppMode.WORKFLOW]:+ if app_mode in {AppMode.ADVANCED_CHAT, AppMode.WORKFLOW}:app = cls._import_and_create_new_workflow_based_app(tenant_id=tenant_id,app_mode=app_mode,@@ -103,7 +103,7 @@ class AppDslService:icon_background=icon_background,use_icon_as_answer_icon=use_icon_as_answer_icon,)- elif app_mode in [AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.COMPLETION]:+ elif app_mode in {AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.COMPLETION}:app = cls._import_and_create_new_model_config_based_app(tenant_id=tenant_id,app_mode=app_mode,@@ -143,7 +143,7 @@ class AppDslService:# import dsl and overwrite appapp_mode = AppMode.value_of(app_data.get("mode"))- if app_mode not in [AppMode.ADVANCED_CHAT, AppMode.WORKFLOW]:+ if app_mode not in {AppMode.ADVANCED_CHAT, AppMode.WORKFLOW}:raise ValueError("Only support import workflow in advanced-chat or workflow app.")if app_data.get("mode") != app_model.mode:@@ -177,7 +177,7 @@ class AppDslService:},}- if app_mode in [AppMode.ADVANCED_CHAT, AppMode.WORKFLOW]:+ if app_mode in {AppMode.ADVANCED_CHAT, AppMode.WORKFLOW}:cls._append_workflow_export_data(export_data=export_data, app_model=app_model, include_secret=include_secret)diff --git a/api/services/app_service.py b/api/services/app_service.pyindex 1dacfea2463..ac45d623e84 100644--- a/api/services/app_service.py+++ b/api/services/app_service.py@@ -316,7 +316,7 @@ class AppService:meta = {"tool_icons": {}}- if app_mode in [AppMode.ADVANCED_CHAT, AppMode.WORKFLOW]:+ if app_mode in {AppMode.ADVANCED_CHAT, AppMode.WORKFLOW}:workflow = app_model.workflowif workflow is None:return metadiff --git a/api/services/audio_service.py b/api/services/audio_service.pyindex 05cd1c96a1d..7a0cd5725b2 100644--- a/api/services/audio_service.py+++ b/api/services/audio_service.py@@ -25,7 +25,7 @@ logger = logging.getLogger(__name__)class AudioService:@classmethoddef transcript_asr(cls, app_model: App, file: FileStorage, end_user: Optional[str] = None):- if app_model.mode in [AppMode.ADVANCED_CHAT.value, AppMode.WORKFLOW.value]:+ if app_model.mode in {AppMode.ADVANCED_CHAT.value, AppMode.WORKFLOW.value}:workflow = app_model.workflowif workflow is None:raise ValueError("Speech to text is not enabled")@@ -83,7 +83,7 @@ class AudioService:def invoke_tts(text_content: str, app_model, voice: Optional[str] = None):with app.app_context():- if app_model.mode in [AppMode.ADVANCED_CHAT.value, AppMode.WORKFLOW.value]:+ if app_model.mode in {AppMode.ADVANCED_CHAT.value, AppMode.WORKFLOW.value}:workflow = app_model.workflowif workflow is None:raise ValueError("TTS is not enabled")diff --git a/api/services/auth/firecrawl.py b/api/services/auth/firecrawl.pyindex 30e4ee57c06..afc491398f2 100644--- a/api/services/auth/firecrawl.py+++ b/api/services/auth/firecrawl.py@@ -37,7 +37,7 @@ class FirecrawlAuth(ApiKeyAuthBase):return requests.post(url, headers=headers, json=data)def _handle_error(self, response):- if response.status_code in [402, 409, 500]:+ if response.status_code in {402, 409, 500}:error_message = response.json().get("error", "Unknown error occurred")raise Exception(f"Failed to authorize. Status code: {response.status_code}. Error: {error_message}")else:diff --git a/api/services/dataset_service.py b/api/services/dataset_service.pyindex fa017bfa42a..30c010ef29f 100644--- a/api/services/dataset_service.py+++ b/api/services/dataset_service.py@@ -544,7 +544,7 @@ class DocumentService:@staticmethoddef pause_document(document):- if document.indexing_status not in ["waiting", "parsing", "cleaning", "splitting", "indexing"]:+ if document.indexing_status not in {"waiting", "parsing", "cleaning", "splitting", "indexing"}:raise DocumentIndexingError()# update document to be pauseddocument.is_paused = Truediff --git a/api/services/tools/tools_transform_service.py b/api/services/tools/tools_transform_service.pyindex 6fb0f2f5173..7ae1b9f2317 100644--- a/api/services/tools/tools_transform_service.py+++ b/api/services/tools/tools_transform_service.py@@ -33,7 +33,7 @@ class ToolTransformService:if provider_type == ToolProviderType.BUILT_IN.value:return url_prefix + "builtin/" + provider_name + "/icon"- elif provider_type in [ToolProviderType.API.value, ToolProviderType.WORKFLOW.value]:+ elif provider_type in {ToolProviderType.API.value, ToolProviderType.WORKFLOW.value}:try:return json.loads(icon)except:diff --git a/api/services/workflow_service.py b/api/services/workflow_service.pyindex 357ffd41c12..0ff81f1f7e8 100644--- a/api/services/workflow_service.py+++ b/api/services/workflow_service.py@@ -295,7 +295,7 @@ class WorkflowService:# chatbot convert to workflow modeworkflow_converter = WorkflowConverter()- if app_model.mode not in [AppMode.CHAT.value, AppMode.COMPLETION.value]:+ if app_model.mode not in {AppMode.CHAT.value, AppMode.COMPLETION.value}:raise ValueError(f"Current App mode: {app_model.mode} is not supported convert to workflow.")# convert to workflowdiff --git a/api/tasks/recover_document_indexing_task.py b/api/tasks/recover_document_indexing_task.pyindex 21ea11d4dd7..934eb7430c9 100644--- a/api/tasks/recover_document_indexing_task.py+++ b/api/tasks/recover_document_indexing_task.py@@ -29,7 +29,7 @@ def recover_document_indexing_task(dataset_id: str, document_id: str):try:indexing_runner = IndexingRunner()- if document.indexing_status in ["waiting", "parsing", "cleaning"]:+ if document.indexing_status in {"waiting", "parsing", "cleaning"}:indexing_runner.run([document])elif document.indexing_status == "splitting":indexing_runner.run_in_splitting_status(document)diff --git a/api/tests/integration_tests/model_runtime/__mock/google.py b/api/tests/integration_tests/model_runtime/__mock/google.pyindex bc0684086f0..402bd9c2c21 100644--- a/api/tests/integration_tests/model_runtime/__mock/google.py+++ b/api/tests/integration_tests/model_runtime/__mock/google.py@@ -1,15 +1,13 @@from collections.abc import Generator-import google.generativeai.types.content_types as content_typesimport google.generativeai.types.generation_types as generation_config_types-import google.generativeai.types.safety_types as safety_typesimport pytestfrom _pytest.monkeypatch import MonkeyPatchfrom google.ai import generativelanguage as glmfrom google.ai.generativelanguage_v1beta.types import content as gag_contentfrom google.generativeai import GenerativeModelfrom google.generativeai.client import _ClientManager, configure-from google.generativeai.types import GenerateContentResponse+from google.generativeai.types import GenerateContentResponse, content_types, safety_typesfrom google.generativeai.types.generation_types import BaseGenerateContentResponsecurrent_api_key = ""diff --git a/api/tests/integration_tests/model_runtime/__mock/openai_chat.py b/api/tests/integration_tests/model_runtime/__mock/openai_chat.pyindex d9cd7b046e0..439f7d56e9b 100644--- a/api/tests/integration_tests/model_runtime/__mock/openai_chat.py+++ b/api/tests/integration_tests/model_runtime/__mock/openai_chat.py@@ -6,7 +6,6 @@ from time import time# import monkeypatchfrom typing import Any, Literal, Optional, Union-import openai.types.chat.completion_create_params as completion_create_paramsfrom openai import AzureOpenAI, OpenAIfrom openai._types import NOT_GIVEN, NotGivenfrom openai.resources.chat.completions import Completions@@ -18,6 +17,7 @@ from openai.types.chat import (ChatCompletionMessageToolCall,ChatCompletionToolChoiceOptionParam,ChatCompletionToolParam,+ completion_create_params,)from openai.types.chat.chat_completion import ChatCompletion as _ChatCompletionfrom openai.types.chat.chat_completion import Choice as _ChatCompletionChoice@@ -254,7 +254,7 @@ class MockChatClass:"gpt-3.5-turbo-16k-0613",]azure_openai_models = ["gpt35", "gpt-4v", "gpt-35-turbo"]- if not re.match(r"^(https?):\/\/[^\s\/$.?#].[^\s]*$", self._client.base_url.__str__()):+ if not re.match(r"^(https?):\/\/[^\s\/$.?#].[^\s]*$", str(self._client.base_url)):raise InvokeAuthorizationError("Invalid base url")if model in openai_models + azure_openai_models:if not re.match(r"sk-[a-zA-Z0-9]{24,}$", self._client.api_key) and type(self._client) == OpenAI:diff --git a/api/tests/integration_tests/model_runtime/__mock/openai_completion.py b/api/tests/integration_tests/model_runtime/__mock/openai_completion.pyindex c27e89248f4..14223668e03 100644--- a/api/tests/integration_tests/model_runtime/__mock/openai_completion.py+++ b/api/tests/integration_tests/model_runtime/__mock/openai_completion.py@@ -112,7 +112,7 @@ class MockCompletionsClass:]azure_openai_models = ["gpt-35-turbo-instruct"]- if not re.match(r"^(https?):\/\/[^\s\/$.?#].[^\s]*$", self._client.base_url.__str__()):+ if not re.match(r"^(https?):\/\/[^\s\/$.?#].[^\s]*$", str(self._client.base_url)):raise InvokeAuthorizationError("Invalid base url")if model in openai_models + azure_openai_models:if not re.match(r"sk-[a-zA-Z0-9]{24,}$", self._client.api_key) and type(self._client) == OpenAI:diff --git a/api/tests/integration_tests/model_runtime/__mock/openai_embeddings.py b/api/tests/integration_tests/model_runtime/__mock/openai_embeddings.pyindex 025913cb17a..e27b9891f5c 100644--- a/api/tests/integration_tests/model_runtime/__mock/openai_embeddings.py+++ b/api/tests/integration_tests/model_runtime/__mock/openai_embeddings.py@@ -22,7 +22,7 @@ class MockEmbeddingsClass:if isinstance(input, str):input = [input]- if not re.match(r"^(https?):\/\/[^\s\/$.?#].[^\s]*$", self._client.base_url.__str__()):+ if not re.match(r"^(https?):\/\/[^\s\/$.?#].[^\s]*$", str(self._client.base_url)):raise InvokeAuthorizationError("Invalid base url")if len(self._client.api_key) < 18:diff --git a/api/tests/integration_tests/model_runtime/__mock/openai_moderation.py b/api/tests/integration_tests/model_runtime/__mock/openai_moderation.pyindex 270a88e85ff..4262d40f3e5 100644--- a/api/tests/integration_tests/model_runtime/__mock/openai_moderation.py+++ b/api/tests/integration_tests/model_runtime/__mock/openai_moderation.py@@ -20,7 +20,7 @@ class MockModerationClass:if isinstance(input, str):input = [input]- if not re.match(r"^(https?):\/\/[^\s\/$.?#].[^\s]*$", self._client.base_url.__str__()):+ if not re.match(r"^(https?):\/\/[^\s\/$.?#].[^\s]*$", str(self._client.base_url)):raise InvokeAuthorizationError("Invalid base url")if len(self._client.api_key) < 18:diff --git a/api/tests/integration_tests/model_runtime/__mock/openai_speech2text.py b/api/tests/integration_tests/model_runtime/__mock/openai_speech2text.pyindex ef361e86139..a51dcab4be7 100644--- a/api/tests/integration_tests/model_runtime/__mock/openai_speech2text.py+++ b/api/tests/integration_tests/model_runtime/__mock/openai_speech2text.py@@ -20,7 +20,7 @@ class MockSpeech2TextClass:temperature: float | NotGiven = NOT_GIVEN,**kwargs: Any,) -> Transcription:- if not re.match(r"^(https?):\/\/[^\s\/$.?#].[^\s]*$", self._client.base_url.__str__()):+ if not re.match(r"^(https?):\/\/[^\s\/$.?#].[^\s]*$", str(self._client.base_url)):raise InvokeAuthorizationError("Invalid base url")if len(self._client.api_key) < 18:diff --git a/api/tests/integration_tests/model_runtime/__mock/xinference.py b/api/tests/integration_tests/model_runtime/__mock/xinference.pyindex 777737187e2..299523f4f5b 100644--- a/api/tests/integration_tests/model_runtime/__mock/xinference.py+++ b/api/tests/integration_tests/model_runtime/__mock/xinference.py@@ -42,7 +42,7 @@ class MockXinferenceClass:model_uid = url.split("/")[-1] or ""if not re.match(r"[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}", model_uid- ) and model_uid not in ["generate", "chat", "embedding", "rerank"]:+ ) and model_uid not in {"generate", "chat", "embedding", "rerank"}:response.status_code = 404response._content = b"{}"return response@@ -53,7 +53,7 @@ class MockXinferenceClass:response._content = b"{}"return response- if model_uid in ["generate", "chat"]:+ if model_uid in {"generate", "chat"}:response.status_code = 200response._content = b"""{"model_type": "LLM",diff --git a/api/tests/integration_tests/workflow/nodes/test_parameter_extractor.py b/api/tests/integration_tests/workflow/nodes/test_parameter_extractor.pyindex cbe9c5914f1..88435c40227 100644--- a/api/tests/integration_tests/workflow/nodes/test_parameter_extractor.py+++ b/api/tests/integration_tests/workflow/nodes/test_parameter_extractor.py@@ -411,5 +411,5 @@ def test_chat_parameter_extractor_with_memory(setup_anthropic_mock):if latest_role is not None:assert latest_role != prompt.get("role")- if prompt.get("role") in ["user", "assistant"]:+ if prompt.get("role") in {"user", "assistant"}:latest_role = prompt.get("role")diff --git a/api/tests/unit_tests/core/workflow/graph_engine/test_graph_engine.py b/api/tests/unit_tests/core/workflow/graph_engine/test_graph_engine.pyindex a2d71d61fce..197288adba3 100644--- a/api/tests/unit_tests/core/workflow/graph_engine/test_graph_engine.py+++ b/api/tests/unit_tests/core/workflow/graph_engine/test_graph_engine.py@@ -210,7 +210,7 @@ def test_run_parallel_in_workflow(mock_close, mock_remove):assert not isinstance(item, NodeRunFailedEvent)assert not isinstance(item, GraphRunFailedEvent)- if isinstance(item, BaseNodeEvent) and item.route_node_state.node_id in ["llm2", "llm3", "end1", "end2"]:+ if isinstance(item, BaseNodeEvent) and item.route_node_state.node_id in {"llm2", "llm3", "end1", "end2"}:assert item.parallel_id is not Noneassert len(items) == 18@@ -315,12 +315,12 @@ def test_run_parallel_in_chatflow(mock_close, mock_remove):assert not isinstance(item, NodeRunFailedEvent)assert not isinstance(item, GraphRunFailedEvent)- if isinstance(item, BaseNodeEvent) and item.route_node_state.node_id in [+ if isinstance(item, BaseNodeEvent) and item.route_node_state.node_id in {"answer2","answer3","answer4","answer5",- ]:+ }:assert item.parallel_id is not Noneassert len(items) == 23