[Kimi K3 Bug] Fix kimi k3 reasoning parser (#57098)
Signed-off-by: yewentao256 <zhyanwentao@126.com> Co-authored-by: Flora Feng <4florafeng@gmail.com>
This commit is contained in:
@@ -256,11 +256,13 @@ class KimiK3ReasoningParser(ReasoningParser):
|
||||
) -> tuple[str | None, str | None]:
|
||||
"""Split full text into ``(reasoning, rest)`` for the non-streaming path.
|
||||
|
||||
Handles three shapes:
|
||||
* no think channel at all -> ``(None, model_output)`` (all content)
|
||||
Handles four shapes:
|
||||
* response opener without think markers -> no think channel; all content
|
||||
* open marker present -> reasoning starts after ``<|open|>think<|sep|>``
|
||||
* open marker absent but a close marker exists (gen-prefix consumed
|
||||
the open) -> reasoning starts at offset 0
|
||||
* neither marker present -> truncated reasoning after a consumed
|
||||
generation prefix
|
||||
``rest`` is whatever follows the close marker, fed on to the tool parser.
|
||||
"""
|
||||
if not self._thinking_enabled:
|
||||
@@ -270,11 +272,14 @@ class KimiK3ReasoningParser(ReasoningParser):
|
||||
# reasoning content begins right after think-open (or at start if the
|
||||
# open marker was already consumed as a generation prefix)
|
||||
content_start = m_open.end() if m_open is not None else 0
|
||||
# if there is no think channel at all, everything is content
|
||||
if m_open is None and self._think_close_re.search(model_output) is None:
|
||||
return None, self._content_after_reasoning(model_output, request)
|
||||
|
||||
m_close = self._think_close_re.search(model_output, content_start)
|
||||
if (
|
||||
m_open is None
|
||||
and m_close is None
|
||||
and self._response_open_re.search(model_output) is not None
|
||||
):
|
||||
return None, self._content_after_reasoning(model_output, request)
|
||||
if m_close is not None:
|
||||
reasoning = model_output[content_start : m_close.start()]
|
||||
rest = model_output[m_close.end() :]
|
||||
|
||||
Reference in New Issue
Block a user