add kia ai chat tools16
CI/CD Pipeline / build-and-deploy (push) Successful in 19s
Details
CI/CD Pipeline / build-and-deploy (push) Successful in 19s
Details
This commit is contained in:
parent
b94402df6b
commit
1ece942eba
|
|
@ -122,6 +122,10 @@ class KiaAIService:
|
|||
Core SSE parser — yields one AIMessageChunk per content delta token.
|
||||
Final chunk: AIMessageChunk(content="", usage_metadata={...}).
|
||||
Raises RuntimeError on KIA server errors (triggers retry in stream()).
|
||||
|
||||
Uses aiter_bytes(chunk_size=32) instead of aiter_lines() so every
|
||||
byte received from the network is processed immediately without
|
||||
waiting for httpx's internal 64 KB read buffer to fill up.
|
||||
"""
|
||||
usage: dict = {}
|
||||
|
||||
|
|
@ -139,7 +143,15 @@ class KiaAIService:
|
|||
resp.raise_for_status()
|
||||
|
||||
line_count = 0
|
||||
async for line in resp.aiter_lines():
|
||||
buf = ""
|
||||
done = False
|
||||
|
||||
async for raw in resp.aiter_bytes(chunk_size=32):
|
||||
buf += raw.decode("utf-8", errors="replace")
|
||||
|
||||
while "\n" in buf:
|
||||
line, buf = buf.split("\n", 1)
|
||||
line = line.rstrip("\r")
|
||||
line_count += 1
|
||||
if line_count <= 3:
|
||||
print(f"[KiaAI] raw[{line_count}]: {line!r}")
|
||||
|
|
@ -165,6 +177,7 @@ class KiaAIService:
|
|||
|
||||
if raw_data.strip() == "[DONE]":
|
||||
print("[KiaAI] [DONE]")
|
||||
done = True
|
||||
break
|
||||
|
||||
try:
|
||||
|
|
@ -190,6 +203,9 @@ class KiaAIService:
|
|||
if data.get("usage"):
|
||||
usage = data["usage"]
|
||||
|
||||
if done:
|
||||
break
|
||||
|
||||
# Final chunk carries usage metadata
|
||||
print(f"[KiaAI] Stream done | total_lines={line_count} | usage={usage}")
|
||||
yield AIMessageChunk(
|
||||
|
|
|
|||
Loading…
Reference in New Issue