polish code with new pre-commit rule (#2923)

This commit is contained in:
Zero Rains
2025-07-19 23:19:27 +08:00
committed by GitHub
parent b8676d71a8
commit 25698d56d1
424 changed files with 14307 additions and 13518 deletions

View File

@@ -13,13 +13,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""
from abc import abstractmethod
from collections.abc import Sequence
from functools import cached_property
from typing import Callable, Optional, Union
from fastdeploy.entrypoints.openai.protocol import (ChatCompletionRequest,
DeltaMessage)
from fastdeploy.entrypoints.openai.protocol import ChatCompletionRequest, DeltaMessage
from fastdeploy.utils import is_list_of
@@ -72,7 +72,7 @@ class ReasoningParser:
@abstractmethod
def extract_reasoning_content(
self, model_output: str, request: ChatCompletionRequest
self, model_output: str, request: ChatCompletionRequest
) -> tuple[Optional[str], Optional[str]]:
"""
Extract reasoning content from a complete model-generated string.
@@ -115,11 +115,11 @@ class ReasoningParserManager:
"""
ReasoningParserManager
"""
reasoning_parsers: dict[str, type] = {}
@classmethod
def get_reasoning_parser(cls,
name: Optional[str]) -> type[ReasoningParser]:
def get_reasoning_parser(cls, name: Optional[str]) -> type[ReasoningParser]:
"""
Get reasoning parser by name which is registered by `register_module`.
@@ -128,8 +128,7 @@ class ReasoningParserManager:
if name in cls.reasoning_parsers:
return cls.reasoning_parsers[name]
raise KeyError(
f"reasoning helper: '{name}' not found in reasoning_parsers")
raise KeyError(f"reasoning helper: '{name}' not found in reasoning_parsers")
@classmethod
def _register_module(
@@ -139,8 +138,7 @@ class ReasoningParserManager:
force: bool = True,
) -> None:
if not issubclass(module, ReasoningParser):
raise TypeError("module must be subclass of ReasoningParser, "
f"but got {type(module)}")
raise TypeError("module must be subclass of ReasoningParser, " f"but got {type(module)}")
if module_name is None:
module_name = module.__name__
if isinstance(module_name, str):
@@ -148,8 +146,7 @@ class ReasoningParserManager:
for name in module_name:
if not force and name in cls.reasoning_parsers:
existed_module = cls.reasoning_parsers[name]
raise KeyError(f"{name} is already registered "
f"at {existed_module.__module__}")
raise KeyError(f"{name} is already registered " f"at {existed_module.__module__}")
cls.reasoning_parsers[name] = module
@classmethod
@@ -168,11 +165,8 @@ class ReasoningParserManager:
raise TypeError(f"force must be a boolean, but got {type(force)}")
# raise the error ahead of time
if not (name is None or isinstance(name, str)
or is_list_of(name, str)):
raise TypeError(
"name must be None, an instance of str, or a sequence of str, "
f"but got {type(name)}")
if not (name is None or isinstance(name, str) or is_list_of(name, str)):
raise TypeError("name must be None, an instance of str, or a sequence of str, " f"but got {type(name)}")
# use it as a normal method: x.register_module(module=SomeClass)
if module is not None: