fix(http): force UTF-8 decoding on the SSE chat stream

llama.cpp sends the streaming response as text/event-stream WITHOUT a charset;
requests then does not decode as UTF-8, so iter_lines(decode_unicode=True)
mangled multibyte characters (German Umlaute) into double-encoded garbage
(e.g. "schön" -> "schön"). The non-streaming path via resp.json() was fine.

Set resp.encoding = "utf-8" before iter_lines. Verified live: streamed bytes for
"schön" are now c3 b6 (correct UTF-8), file detected as UTF-8.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Dieter Schlüter 2026-07-06 18:47:50 +02:00
commit 1b9c08efcb
2 changed files with 6 additions and 0 deletions

View file

@ -163,6 +163,8 @@ def test_stream_chat_yields_content_and_finish():
finishes = [v for k, v in events if k == "finish"]
assert "".join(contents) == "Hallo"
assert finishes == ["stop"]
# Stream must be forced to UTF-8 (llama.cpp sends no charset -> Umlaut-Bug).
assert mock_resp.encoding == "utf-8"
def test_wait_until_ready_succeeds_immediately():