add kia ai chat tools20
CI/CD Pipeline / build-and-deploy (push) Successful in 18s
Details
CI/CD Pipeline / build-and-deploy (push) Successful in 18s
Details
This commit is contained in:
parent
1e46711ab0
commit
04fd4253e0
|
|
@ -1,4 +1,5 @@
|
||||||
import json
|
import json
|
||||||
|
import codecs
|
||||||
import asyncio
|
import asyncio
|
||||||
from typing import AsyncGenerator
|
from typing import AsyncGenerator
|
||||||
import httpx
|
import httpx
|
||||||
|
|
@ -145,9 +146,12 @@ class KiaAIService:
|
||||||
line_count = 0
|
line_count = 0
|
||||||
buf = ""
|
buf = ""
|
||||||
done = False
|
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):
|
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:
|
while "\n" in buf:
|
||||||
line, buf = buf.split("\n", 1)
|
line, buf = buf.split("\n", 1)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue