add kia ai chat tools20
CI/CD Pipeline / build-and-deploy (push) Successful in 18s Details

This commit is contained in:
vahidrezvani 2026-02-28 09:44:05 +03:30
parent 1e46711ab0
commit 04fd4253e0
1 changed files with 5 additions and 1 deletions

View File

@ -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)