Skip to content

Commit dae8419

Browse files
committed
fix parser
1 parent 3b93672 commit dae8419

File tree

2 files changed

+6
-15
lines changed

2 files changed

+6
-15
lines changed

fastdeploy/entrypoints/openai/tool_parsers/ernie_x1_tool_parser.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,14 @@ def __init__(self, tokenizer):
5858
self.tool_call_start_token_id = self.vocab.get(self.tool_call_start_token)
5959
self.tool_call_end_token_id = self.vocab.get(self.tool_call_end_token)
6060
if self.tool_call_start_token_id is None or self.tool_call_end_token_id is None:
61-
raise RuntimeError(
62-
"Hermes 2 Pro Tool parser could not locate tool call start/end " "tokens in the tokenizer!"
63-
)
61+
raise RuntimeError("Ernie x1 Tool parser could not locate tool call start/end " "tokens in the tokenizer!")
6462

6563
if not self.model_tokenizer:
6664
raise ValueError(
6765
"The model tokenizer must be passed to the ToolCallParser constructor during construction."
6866
)
6967

70-
def extract_tool_calls(
71-
self, model_output: str, request: ChatCompletionRequest, model_status: str
72-
) -> ExtractedToolCallInformation:
68+
def extract_tool_calls(self, model_output: str, request: ChatCompletionRequest) -> ExtractedToolCallInformation:
7369
"""
7470
Extract the tool calls from a complete model response.
7571
Supports XML-style formats with newlines:
@@ -81,13 +77,10 @@ def extract_tool_calls(
8177
3. Only name and arguments field without content: {"name": "get_weather", "argume
8278
"""
8379

84-
extract_content = model_output
85-
if model_status == "tool_call_start":
86-
extract_content = "<tool_call>" + model_output
8780
try:
88-
if self.tool_call_start_token not in extract_content:
81+
if self.tool_call_start_token not in model_output:
8982
return ExtractedToolCallInformation(tools_called=False, tool_calls=[], content=model_output)
90-
function_call_tuples = self.tool_call_regex.findall(extract_content)
83+
function_call_tuples = self.tool_call_regex.findall(model_output)
9184

9285
raw_function_calls = [json.loads(match[0] if match[0] else match[1]) for match in function_call_tuples]
9386

@@ -116,7 +109,6 @@ def extract_tool_calls_streaming(
116109
current_token_ids: Sequence[int],
117110
delta_token_ids: Sequence[int],
118111
request: dict,
119-
model_status: str,
120112
) -> Union[DeltaMessage, None]:
121113

122114
if self.tool_call_start_token_id not in current_token_ids:

fastdeploy/input/ernie4_5_processor.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,10 @@ def process_response_dict_normal(self, response_dict, **kwargs):
323323
response_dict["outputs"]["reasoning_content"] = reasoning_content
324324
if self.tool_parser_obj:
325325
tool_parser = self.tool_parser_obj(self.tokenizer)
326-
tool_call_info = tool_parser.extract_tool_calls(full_text, response_dict, model_status)
326+
tool_call_info = tool_parser.extract_tool_calls(full_text, response_dict)
327327
if tool_call_info.tools_called:
328328
response_dict["outputs"]["tool_call"] = tool_call_info.tool_calls
329-
response_dict["outputs"]["text"] = tool_call_info.content
329+
response_dict["outputs"]["text"] = tool_call_info.content
330330
response_dict["outputs"]["raw_prediction"] = full_text
331331
data_processor_logger.info(f"req_id:{req_id}, decode_status: {self.decode_status[req_id]}")
332332
del self.decode_status[req_id]
@@ -378,7 +378,6 @@ def process_response_dict_streaming(self, response_dict, **kwargs):
378378
previous_token_ids + token_ids,
379379
token_ids,
380380
response_dict,
381-
model_status,
382381
)
383382
if tool_call_delta_message is None or tool_call_delta_message.tool_calls:
384383
response_dict["outputs"]["delta_message"] = tool_call_delta_message

0 commit comments

Comments
 (0)