add reasoning parser plugin (#3811)

* add reasoning parser plugin

* fix finish reason
This commit is contained in:
luukunn
2025-09-03 18:31:27 +08:00
committed by GitHub
parent 31313e0f3d
commit fc598d4c5a
5 changed files with 51 additions and 5 deletions

View File

@@ -325,7 +325,9 @@ class OpenAIServingChat:
continue
delta_message.content = delta_message_output.content or ""
delta_message.reasoning_content = delta_message_output.reasoning_content or ""
delta_message.tool_calls = delta_message_output.tool_calls
if delta_message_output.tool_calls:
delta_message.tool_calls = delta_message_output.tool_calls
tool_called = True
choice = ChatCompletionResponseStreamChoice(
index=0,

View File

@@ -418,7 +418,9 @@ class OpenAIServingCompletion:
continue
delta_message.text = delta_message_output.content or ""
delta_message.reasoning_content = delta_message_output.reasoning_content or ""
delta_message.tool_calls = delta_message_output.tool_calls
if delta_message_output.tool_calls:
delta_message.tool_calls = delta_message_output.tool_calls
tool_called[idx] = True
choices.append(delta_message)

View File

@@ -71,8 +71,15 @@ class InputPreprocessor:
"""
reasoning_parser_obj = None
tool_parser_obj = None
if self.reasoning_parser:
reasoning_parser_obj = ReasoningParserManager.get_reasoning_parser(self.reasoning_parser)
try:
from fastdeploy.plugins.reasoning_parser import (
load_reasoning_parser_plugins,
)
reasoning_parser_obj = load_reasoning_parser_plugins()
except:
if self.reasoning_parser:
reasoning_parser_obj = ReasoningParserManager.get_reasoning_parser(self.reasoning_parser)
if self.tool_parser:
tool_parser_obj = ToolParserManager.get_tool_parser(self.tool_parser)
@@ -85,6 +92,8 @@ class InputPreprocessor:
Processor = load_input_processor_plugins()
self.processor = Processor(
model_name_or_path=self.model_name_or_path,
reasoning_parser_obj=reasoning_parser_obj,
tool_parser_obj=tool_parser_obj,
)
except:
if not self.enable_mm:

View File

@@ -17,5 +17,11 @@
from .input_processor import load_input_processor_plugins
from .model_register import load_model_register_plugins
from .model_runner import load_model_runner_plugins
from .reasoning_parser import load_reasoning_parser_plugins
__all__ = ["load_model_register_plugins", "load_model_runner_plugins", "load_input_processor_plugins"]
__all__ = [
"load_model_register_plugins",
"load_model_runner_plugins",
"load_input_processor_plugins",
"load_reasoning_parser_plugins",
]

View File

@@ -0,0 +1,27 @@
"""
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
from fastdeploy.plugins.utils import load_plugins_by_group
# make sure one process only loads plugins once
PLUGINS_GROUP = "fastdeploy.reasoning_parser_plugins"
def load_reasoning_parser_plugins():
"""load_reasoning_parser_plugins"""
plugins = load_plugins_by_group(group=PLUGINS_GROUP)
assert len(plugins) <= 1, "Most one plugin is allowed to be loaded."
return next(iter(plugins.values()))()