【Optimization】update data_processor & add tool parser plugins (#6096)

* update data_processor

* fix unit test

* fix unit test

* add unit test

* add tool parser plugins

* fix tool call

* fix tool call

* fix tool call

* fix unit test

* fix unit test

* add unit test

* fix unit test

* fix unit test

* fix unit test
This commit is contained in:
luukunn
2026-01-22 17:17:32 +08:00
committed by GitHub
parent 955785e2e0
commit 6b968a76f1
13 changed files with 871 additions and 1013 deletions
+21 -16
View File
@@ -341,7 +341,7 @@ class Ernie4_5Processor(BaseDataProcessor):
tool_parser = self.tool_parser_obj(self.tokenizer)
tool_call_info = tool_parser.extract_tool_calls(full_text, response_dict)
if tool_call_info.tools_called:
response_dict["outputs"]["tool_call"] = tool_call_info.tool_calls
response_dict["outputs"]["tool_calls"] = tool_call_info.tool_calls
response_dict["outputs"]["text"] = tool_call_info.content
response_dict["outputs"]["completion_tokens"] = full_text
data_processor_logger.info(f"req_id:{req_id}, decode_status: {self.decode_status[req_id]}")
@@ -369,7 +369,11 @@ class Ernie4_5Processor(BaseDataProcessor):
if token_ids[-1] == self.tokenizer.eos_token_id:
token_ids = token_ids[:-1]
delta_text, previous_token_ids, previous_texts = self.ids2tokens(token_ids, req_id)
response_dict["outputs"]["text"] = delta_text
response_dict["outputs"]["completion_tokens"] = delta_text
response_dict["outputs"]["skipped"] = False
response_dict["outputs"]["tool_calls"] = None
response_dict["outputs"]["reasoning_content"] = ""
if self.reasoning_parser:
reasoning_delta_message = self.reasoning_parser.extract_reasoning_content_streaming(
previous_texts,
@@ -380,19 +384,15 @@ class Ernie4_5Processor(BaseDataProcessor):
token_ids,
self.model_status_dict[req_id],
)
response_dict["outputs"]["enable_parser"] = True
response_dict["outputs"]["delta_message"] = reasoning_delta_message
reasoning_content = reasoning_delta_message.reasoning_content if reasoning_delta_message else None
reasoning_tokens = self.tokenizer.tokenize(reasoning_content) if reasoning_content else []
response_dict["outputs"]["reasoning_token_num"] = len(reasoning_tokens)
response_dict["outputs"]["reasoning_content"] = reasoning_content
response_dict["outputs"]["text"] = (
reasoning_delta_message.content or ""
if reasoning_delta_message and hasattr(reasoning_delta_message, "content")
else ""
)
else:
response_dict["outputs"]["text"] = delta_text
if reasoning_delta_message:
reasoning_content = reasoning_delta_message.reasoning_content
reasoning_tokens = self.tokenizer.tokenize(reasoning_content) if reasoning_content else []
response_dict["outputs"]["reasoning_token_num"] = len(reasoning_tokens)
response_dict["outputs"]["reasoning_content"] = reasoning_content or ""
response_dict["outputs"]["text"] = reasoning_delta_message.content or ""
else:
if not is_end:
response_dict["outputs"]["skipped"] = True
if self.tool_parser_obj:
response_dict["outputs"]["enable_parser"] = True
if req_id not in self.tool_parser_dict:
@@ -407,8 +407,13 @@ class Ernie4_5Processor(BaseDataProcessor):
token_ids,
response_dict,
)
if tool_call_delta_message is None or tool_call_delta_message.tool_calls:
response_dict["outputs"]["delta_message"] = tool_call_delta_message
if tool_call_delta_message:
if tool_call_delta_message.tool_calls:
response_dict["outputs"]["text"] = tool_call_delta_message.content
response_dict["outputs"]["tool_calls"] = tool_call_delta_message.tool_calls
else:
if not is_end:
response_dict["outputs"]["skipped"] = True
if is_end:
data_processor_logger.info(f"req_id:{req_id}, decode_status: {self.decode_status[req_id]}")