From 04fd4253e0f0a93e77cb44f3ba8844f2f01942df Mon Sep 17 00:00:00 2001 From: vahidrezvani Date: Sat, 28 Feb 2026 09:44:05 +0330 Subject: [PATCH] add kia ai chat tools20 --- src/services/kiaai/chat.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/services/kiaai/chat.py b/src/services/kiaai/chat.py index 8442803..b83e067 100644 --- a/src/services/kiaai/chat.py +++ b/src/services/kiaai/chat.py @@ -1,4 +1,5 @@ import json +import codecs import asyncio from typing import AsyncGenerator import httpx @@ -145,9 +146,12 @@ class KiaAIService: line_count = 0 buf = "" done = False + # Incremental decoder holds partial multi-byte chars (Persian = 2 bytes each) + # until the remaining bytes arrive — prevents '?' corruption with chunk_size=1 + _decoder = codecs.getincrementaldecoder("utf-8")(errors="replace") async for raw in resp.aiter_bytes(chunk_size=1): - buf += raw.decode("utf-8", errors="replace") + buf += _decoder.decode(raw) while "\n" in buf: line, buf = buf.split("\n", 1)