[Cherry-Pick] Fix ernie_vl_reasoning_parsers.py 'end_token' to 'think_end_token' (#4805) (#4842)

* [Feature] add a new reasoning parser (#4571)

* add new reasoning_parser initial commit

* add parser file content

* add register

* ernie_test_reasoning_parser

* support <tool_call> token and add tool_parser

* add and fix unit tests

* modify reasoning_parser

* modify reasoning parser and tool parser

* modify unit tests

* modify reasoning_parser and tool_parser

* modify unit tests

* fix tool_parser

* modify the logic of reasoning_parser and tool_parser

* add and modify unit tests

* standardize code style

* simplify reasoning_parser and tool_parser

* modify unit test

* [BugFix] Fix finish reason in _create_chat_completion_choice  (#4582)

* fix n_param _create_chat_completion_choicel

* fix unit test

* fix final_res

* modify unit tests

* [BugFix] fix offline llm chat "enable_thinking" is always "False" (#4686)

* fix enable_thinking

* recover ernie4_5_vl_processor

* [BugFix] Fix ernie_vl_reasoning_parsers.py 'end_token' to 'think_end_token' (#4805)

* fix ernie_vl_reasoning_parsers.py 'end_token' to 'think_end_token'

* add unit tests
This commit is contained in:
kxz2002
2025-11-06 15:54:48 +08:00
committed by GitHub
parent 8e48da8027
commit cbe27ad9fb
2 changed files with 58 additions and 2 deletions

View File

@@ -70,9 +70,9 @@ class ErnieVLReasoningParser(ReasoningParser):
if len(delta_token_ids) == 1 and delta_token_ids[0] == self.think_end_token_id:
return None
if self.think_end_token_id in delta_token_ids:
end_index = delta_text.find(self.end_token)
end_index = delta_text.find(self.think_end_token)
reasoning_content = delta_text[:end_index]
content = delta_text[end_index + len(self.end_token) :]
content = delta_text[end_index + len(self.think_end_token) :]
return DeltaMessage(reasoning_content=reasoning_content, content=content)
elif self.think_end_token_id in previous_token_ids:
return DeltaMessage(content=delta_text)

View File

@@ -21,6 +21,7 @@ from fastdeploy.reasoning import ReasoningParser, ReasoningParserManager
from fastdeploy.reasoning.ernie_45_vl_thinking_reasoning_parser import (
Ernie45VLThinkingReasoningParser,
)
from fastdeploy.reasoning.ernie_vl_reasoning_parsers import ErnieVLReasoningParser
from fastdeploy.reasoning.ernie_x1_reasoning_parsers import ErnieX1ReasoningParser
@@ -425,5 +426,60 @@ class TestErnie45VLThinkingReasoningParser(unittest.TestCase):
self.assertEqual(content, "\n\n actual response")
class TestErnieVLReasoningParser(unittest.TestCase):
def setUp(self):
self.tokenizer = DummyTokenizer()
self.parser = ErnieVLReasoningParser(tokenizer=self.tokenizer)
self.test_request = ChatCompletionRequest(
model="ernie-test", messages=[{"role": "user", "content": "test prompt"}]
)
def test_extract_reasoning_content_stream(self):
result = self.parser.extract_reasoning_content_streaming(
previous_text="abc",
current_text="abc</think>xyz",
delta_text="</think>xyz",
previous_token_ids=[200, 201, 202],
current_token_ids=[200, 201, 202, 100, 110, 120, 130],
delta_token_ids=[100, 110, 120, 130],
)
self.assertIsInstance(result, DeltaMessage)
self.assertEqual(result.reasoning_content, "")
self.assertEqual(result.content, "xyz")
def test_extract_reasoning_content_stream_think_in_previous(self):
result = self.parser.extract_reasoning_content_streaming(
previous_text="abc</think>",
current_text="abc</think>xyz",
delta_text="xyz",
previous_token_ids=[200, 201, 202, 100],
current_token_ids=[200, 201, 202, 100, 110, 120, 130],
delta_token_ids=[110, 120, 130],
)
self.assertIsInstance(result, DeltaMessage)
self.assertIsNone(result.reasoning_content)
self.assertEqual(result.content, "xyz")
def test_extract_reasoning_content_stream_no_think_token(self):
result = self.parser.extract_reasoning_content_streaming(
previous_text="abc",
current_text="abcxyz",
delta_text="xyz",
previous_token_ids=[200, 201, 202],
current_token_ids=[200, 201, 202, 110, 120, 130],
delta_token_ids=[110, 120, 130],
)
self.assertIsInstance(result, DeltaMessage)
self.assertIsNone(result.content)
self.assertEqual(result.reasoning_content, "xyz")
def test_extract_reasoning_content(self):
reasoning, content = self.parser.extract_reasoning_content(
model_output="reasoning</think>\nactual response", request=self.test_request
)
self.assertEqual(reasoning, "reasoning")
self.assertEqual(content, "\nactual response")
if __name__ == "__main__":
unittest.main()