fix:Modify the remove_think that directly retrieves the configuration file from the requester, retrieves it from the runner, and passes it to the required function

This commit is contained in:
fdc
2025-08-04 16:36:02 +08:00
committed by Junyan Qin
parent a62b38eda7
commit 8adc88a8c0
10 changed files with 46 additions and 31 deletions
@@ -27,7 +27,7 @@ class PPIOChatCompletions(chatcmpl.OpenAIChatCompletions):
async def _make_msg(
self,
chat_completion: chat_completion.ChatCompletion,
pipeline_config: dict[str, typing.Any] = {'trigger': {'misc': {'remove_think': False}}},
remove_think: bool,
) -> llm_entities.Message:
chatcmpl_message = chat_completion.choices[0].message.model_dump()
# print(chatcmpl_message.keys(), chatcmpl_message.values())
@@ -39,7 +39,7 @@ class PPIOChatCompletions(chatcmpl.OpenAIChatCompletions):
reasoning_content = chatcmpl_message['reasoning_content'] if 'reasoning_content' in chatcmpl_message else None
# deepseek的reasoner模型
if pipeline_config['trigger'].get('misc', '').get('remove_think'):
if remove_think:
chatcmpl_message['content'] = re.sub(
r'<think>.*?</think>', '', chatcmpl_message['content'], flags=re.DOTALL
)
@@ -55,7 +55,7 @@ class PPIOChatCompletions(chatcmpl.OpenAIChatCompletions):
async def _make_msg_chunk(
self,
pipeline_config: dict[str, typing.Any],
remove_think: bool,
chat_completion: chat_completion.ChatCompletion,
idx: int,
) -> llm_entities.MessageChunk:
@@ -79,7 +79,7 @@ class PPIOChatCompletions(chatcmpl.OpenAIChatCompletions):
# print(reasoning_content)
# deepseek的reasoner模型
if pipeline_config['trigger'].get('misc', '').get('remove_think'):
if remove_think:
if '<think>' in delta['content']:
self.is_think = True
delta['content'] = ''
@@ -105,6 +105,7 @@ class PPIOChatCompletions(chatcmpl.OpenAIChatCompletions):
use_model: requester.RuntimeLLMModel,
use_funcs: list[tools_entities.LLMFunction] = None,
extra_args: dict[str, typing.Any] = {},
remove_think: bool = False,
) -> llm_entities.Message | typing.AsyncGenerator[llm_entities.MessageChunk, None]:
self.client.api_key = use_model.token_mgr.get_token()
@@ -136,10 +137,9 @@ class PPIOChatCompletions(chatcmpl.OpenAIChatCompletions):
chunk_idx = 0
self.is_content = False
tool_calls_map: dict[str, llm_entities.ToolCall] = {}
pipeline_config = query.pipeline_config
async for chunk in self._req_stream(args, extra_body=extra_args):
# 处理流式消息
delta_message = await self._make_msg_chunk(pipeline_config, chunk, chunk_idx)
delta_message = await self._make_msg_chunk(remove_think, chunk, chunk_idx)
if delta_message.content:
current_content += delta_message.content
delta_message.content = current_content