Fix dropped Inkling reasoning at stream end (#31787)
This commit is contained in:
@@ -249,6 +249,24 @@ class TestInklingDetector(CustomTestCase):
|
||||
content += detector.parse_streaming_increment(chunk).normal_text
|
||||
self.assertEqual(content, " worldnext", msg=f"chunks={chunks!r}")
|
||||
|
||||
def test_finish_flushes_reasoning_truncated_before_end_token(self):
|
||||
"""Bug regression: with stream_reasoning=False the detector buffers the
|
||||
thinking block and only flushes it on a control/end token. When
|
||||
generation is cut mid-block (e.g. max_tokens) the stream ends with no
|
||||
end token, so the buffered trace was dropped entirely; finish() must
|
||||
emit it, matching the non-streaming detect_and_parse path."""
|
||||
detector = InklingDetector(stream_reasoning=False)
|
||||
source = "<|message_model|><|content_thinking|>truncated thinking"
|
||||
streamed_reasoning = ""
|
||||
for char in source:
|
||||
streamed_reasoning += detector.parse_streaming_increment(
|
||||
char
|
||||
).reasoning_text
|
||||
# The block never closed, so nothing surfaces mid-stream.
|
||||
self.assertEqual(streamed_reasoning, "")
|
||||
# finish() flushes the buffered trace instead of dropping it.
|
||||
self.assertEqual(detector.finish().reasoning_text, "truncated thinking")
|
||||
|
||||
|
||||
class TestKimiDetector(CustomTestCase):
|
||||
def setUp(self):
|
||||
|
||||
Reference in New Issue
Block a user