From d69e536bf04a827edfa5c7f700b921591a0681e5 Mon Sep 17 00:00:00 2001 From: -LAN- Date: Wed, 4 Dec 2024 13:11:04 +0800 Subject: [PATCH] chore: add pre-commit-config and apply format. Signed-off-by: -LAN- --- .pre-commit-config.yaml | 10 ++++++++ python/dify_plugin/core/plugin_executor.py | 24 +++++++++---------- .../dify_plugin/core/plugin_registration.py | 1 - .../core/server/tcp/request_reader.py | 1 - .../interfaces/model/large_language_model.py | 1 + .../model/openai_compatible/speech2text.py | 2 +- .../model/openai_compatible/text_embedding.py | 2 +- .../dify_plugin/interfaces/tool/__init__.py | 3 +-- python/examples/code_based_workflow/main.py | 2 +- python/examples/google/main.py | 2 +- python/examples/jina/main.py | 2 +- 11 files changed, 29 insertions(+), 21 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..bc3aa8e --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,10 @@ +repos: + - repo: https://github.com/astral-sh/ruff-pre-commit + # Ruff version. + rev: v0.8.1 + hooks: + # Run the linter. + - id: ruff + args: [--fix] + # Run the formatter. + - id: ruff-format diff --git a/python/dify_plugin/core/plugin_executor.py b/python/dify_plugin/core/plugin_executor.py index c889e3b..5bf9c3b 100644 --- a/python/dify_plugin/core/plugin_executor.py +++ b/python/dify_plugin/core/plugin_executor.py @@ -5,18 +5,6 @@ from werkzeug import Response from dify_plugin.config.config import DifyPluginEnv -from dify_plugin.core.plugin_registration import PluginRegistration -from dify_plugin.core.runtime import Session -from dify_plugin.core.utils.http_parser import parse_raw_request -from dify_plugin.entities.tool import ToolRuntime -from dify_plugin.interfaces.endpoint import Endpoint -from dify_plugin.interfaces.model.ai_model import AIModel -from dify_plugin.interfaces.model.large_language_model import LargeLanguageModel -from dify_plugin.interfaces.model.moderation_model import ModerationModel -from dify_plugin.interfaces.model.rerank_model import RerankModel -from dify_plugin.interfaces.model.speech2text_model import Speech2TextModel -from dify_plugin.interfaces.model.text_embedding_model import TextEmbeddingModel -from dify_plugin.interfaces.model.tts_model import TTSModel from dify_plugin.core.entities.plugin.request import ( EndpointInvokeRequest, ModelGetAIModelSchemas, @@ -35,6 +23,18 @@ ToolInvokeRequest, ToolValidateCredentialsRequest, ) +from dify_plugin.core.plugin_registration import PluginRegistration +from dify_plugin.core.runtime import Session +from dify_plugin.core.utils.http_parser import parse_raw_request +from dify_plugin.entities.tool import ToolRuntime +from dify_plugin.interfaces.endpoint import Endpoint +from dify_plugin.interfaces.model.ai_model import AIModel +from dify_plugin.interfaces.model.large_language_model import LargeLanguageModel +from dify_plugin.interfaces.model.moderation_model import ModerationModel +from dify_plugin.interfaces.model.rerank_model import RerankModel +from dify_plugin.interfaces.model.speech2text_model import Speech2TextModel +from dify_plugin.interfaces.model.text_embedding_model import TextEmbeddingModel +from dify_plugin.interfaces.model.tts_model import TTSModel class PluginExecutor: diff --git a/python/dify_plugin/core/plugin_registration.py b/python/dify_plugin/core/plugin_registration.py index eb0324f..9be3c10 100644 --- a/python/dify_plugin/core/plugin_registration.py +++ b/python/dify_plugin/core/plugin_registration.py @@ -27,7 +27,6 @@ from dify_plugin.interfaces.model.tts_model import TTSModel from dify_plugin.interfaces.tool import Tool, ToolProvider - T = TypeVar("T") diff --git a/python/dify_plugin/core/server/tcp/request_reader.py b/python/dify_plugin/core/server/tcp/request_reader.py index 7d4de40..24be157 100644 --- a/python/dify_plugin/core/server/tcp/request_reader.py +++ b/python/dify_plugin/core/server/tcp/request_reader.py @@ -8,7 +8,6 @@ from gevent.select import select from dify_plugin.core.entities.message import InitializeMessage - from dify_plugin.core.entities.plugin.io import ( PluginInStream, PluginInStreamEvent, diff --git a/python/dify_plugin/interfaces/model/large_language_model.py b/python/dify_plugin/interfaces/model/large_language_model.py index 56df6ea..cccd9e8 100644 --- a/python/dify_plugin/interfaces/model/large_language_model.py +++ b/python/dify_plugin/interfaces/model/large_language_model.py @@ -29,6 +29,7 @@ SystemPromptMessage, UserPromptMessage, ) + from .ai_model import AIModel logger = logging.getLogger(__name__) diff --git a/python/dify_plugin/interfaces/model/openai_compatible/speech2text.py b/python/dify_plugin/interfaces/model/openai_compatible/speech2text.py index 766b87f..5b27076 100644 --- a/python/dify_plugin/interfaces/model/openai_compatible/speech2text.py +++ b/python/dify_plugin/interfaces/model/openai_compatible/speech2text.py @@ -7,8 +7,8 @@ CredentialsValidateFailedError, InvokeBadRequestError, ) -from dify_plugin.interfaces.model.speech2text_model import Speech2TextModel from dify_plugin.interfaces.model.openai_compatible.common import _CommonOaiApiCompat +from dify_plugin.interfaces.model.speech2text_model import Speech2TextModel class OAICompatSpeech2TextModel(_CommonOaiApiCompat, Speech2TextModel): diff --git a/python/dify_plugin/interfaces/model/openai_compatible/text_embedding.py b/python/dify_plugin/interfaces/model/openai_compatible/text_embedding.py index 44a98e5..c65857a 100644 --- a/python/dify_plugin/interfaces/model/openai_compatible/text_embedding.py +++ b/python/dify_plugin/interfaces/model/openai_compatible/text_embedding.py @@ -23,8 +23,8 @@ from dify_plugin.errors.model import ( CredentialsValidateFailedError, ) -from dify_plugin.interfaces.model.text_embedding_model import TextEmbeddingModel from dify_plugin.interfaces.model.openai_compatible.common import _CommonOaiApiCompat +from dify_plugin.interfaces.model.text_embedding_model import TextEmbeddingModel class OAICompatEmbeddingModel(_CommonOaiApiCompat, TextEmbeddingModel): diff --git a/python/dify_plugin/interfaces/tool/__init__.py b/python/dify_plugin/interfaces/tool/__init__.py index b3bb980..4b96515 100644 --- a/python/dify_plugin/interfaces/tool/__init__.py +++ b/python/dify_plugin/interfaces/tool/__init__.py @@ -2,11 +2,10 @@ from collections.abc import Generator from typing import Any, Optional -from dify_plugin.file.entities import FileType - from dify_plugin.core.runtime import Session from dify_plugin.entities.tool import ToolInvokeMessage, ToolParameter, ToolRuntime from dify_plugin.file.constants import DIFY_FILE_IDENTITY +from dify_plugin.file.entities import FileType from dify_plugin.file.file import File diff --git a/python/examples/code_based_workflow/main.py b/python/examples/code_based_workflow/main.py index 05256da..1bd26de 100644 --- a/python/examples/code_based_workflow/main.py +++ b/python/examples/code_based_workflow/main.py @@ -1,4 +1,4 @@ -from dify_plugin import Plugin, DifyPluginEnv +from dify_plugin import DifyPluginEnv, Plugin plugin = Plugin(DifyPluginEnv(MAX_REQUEST_TIMEOUT=30)) diff --git a/python/examples/google/main.py b/python/examples/google/main.py index 05256da..1bd26de 100644 --- a/python/examples/google/main.py +++ b/python/examples/google/main.py @@ -1,4 +1,4 @@ -from dify_plugin import Plugin, DifyPluginEnv +from dify_plugin import DifyPluginEnv, Plugin plugin = Plugin(DifyPluginEnv(MAX_REQUEST_TIMEOUT=30)) diff --git a/python/examples/jina/main.py b/python/examples/jina/main.py index 05256da..1bd26de 100644 --- a/python/examples/jina/main.py +++ b/python/examples/jina/main.py @@ -1,4 +1,4 @@ -from dify_plugin import Plugin, DifyPluginEnv +from dify_plugin import DifyPluginEnv, Plugin plugin = Plugin(DifyPluginEnv(MAX_REQUEST_TIMEOUT=30))