fix: remove content.strip from pattern 6 (preserve spaces), add logging to except

This commit is contained in:
renearaos 2026-06-19 10:11:54 -04:00
parent 410a4df31e
commit 82f417abfe
2 changed files with 14 additions and 9 deletions

View file

@ -2,9 +2,12 @@
MiniMax OpenAI transformation config - extends OpenAI chat config for MiniMax's OpenAI-compatible API
"""
import logging
import re
from typing import Any, List, Optional, Tuple
logger = logging.getLogger(__name__)
import litellm
from litellm.llms.openai.chat.gpt_transformation import (
OpenAIGPTConfig,
@ -168,9 +171,10 @@ class MinimaxChatResponseIterator(OpenAIChatCompletionStreamingHandler):
elif not self.finished_reasoning_content and content.strip():
if not self.started_reasoning_content:
self.started_reasoning_content = True
delta["reasoning_content"] = content.strip()
delta["reasoning_content"] = content
delta["content"] = None
return super().chunk_parser(chunk)
except Exception:
except Exception as e:
logger.exception("MinimaxChatResponseIterator.chunk_parser error: %s", e)
return super().chunk_parser(chunk)

View file

@ -223,8 +223,6 @@ class TestChunkParserPatterns:
result = it.chunk_parser(chunk)
delta = result.choices[0].delta
assert delta.reasoning_content == "The user wants"
assert delta.content is None
assert it.started_reasoning_content is True
def test_plain_content_skipped_empty_string(self):
"""Empty string content → skip (no reasoning flag)."""
@ -244,11 +242,11 @@ class TestChunkParserPatterns:
c1 = _make_chunk({"content": "first "})
r1 = it.chunk_parser(c1)
assert r1.choices[0].delta.reasoning_content == "first"
assert r1.choices[0].delta.reasoning_content == "first "
c2 = _make_chunk({"content": "second "})
c2 = _make_chunk({"content": " second "})
r2 = it.chunk_parser(c2)
assert r2.choices[0].delta.reasoning_content == "second"
assert r2.choices[0].delta.reasoning_content == " second "
# ------------------------------------------------------------------
# Edge: finish / empty delta
@ -284,10 +282,13 @@ class TestChunkParserPatterns:
# 2-4. plain reasoning chunks
r1 = it.chunk_parser(_make_chunk({"content": "The "}))
assert r1.choices[0].delta.reasoning_content == "The"
assert r1.choices[0].delta.reasoning_content == "The "
r2 = it.chunk_parser(_make_chunk({"content": "user wants "}))
assert r2.choices[0].delta.reasoning_content == "user wants"
assert r2.choices[0].delta.reasoning_content == "user wants "
r3 = it.chunk_parser(_make_chunk({"content": "a greeting."}))
assert r3.choices[0].delta.reasoning_content == "a greeting."
r3 = it.chunk_parser(_make_chunk({"content": "a greeting."}))
assert r3.choices[0].delta.reasoning_content == "a greeting."