mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-09 03:18:44 +00:00
fix: remove content.strip from pattern 6 (preserve spaces), add logging to except
This commit is contained in:
parent
410a4df31e
commit
82f417abfe
2 changed files with 14 additions and 9 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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."
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue