add kia ai chat tools19
CI/CD Pipeline / build-and-deploy (push) Successful in 17s
Details
CI/CD Pipeline / build-and-deploy (push) Successful in 17s
Details
This commit is contained in:
parent
a844bc1b4e
commit
1e46711ab0
|
|
@ -104,7 +104,11 @@ async def send_message(
|
|||
],
|
||||
doc=[(settings.base_url + doc_url) if doc_url else None, doc_path],
|
||||
),
|
||||
media_type="application/json",
|
||||
media_type="application/x-ndjson",
|
||||
headers={
|
||||
"X-Accel-Buffering": "no",
|
||||
"Cache-Control": "no-cache",
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -146,7 +146,7 @@ class KiaAIService:
|
|||
buf = ""
|
||||
done = False
|
||||
|
||||
async for raw in resp.aiter_bytes(chunk_size=32):
|
||||
async for raw in resp.aiter_bytes(chunk_size=1):
|
||||
buf += raw.decode("utf-8", errors="replace")
|
||||
|
||||
while "\n" in buf:
|
||||
|
|
@ -198,6 +198,7 @@ class KiaAIService:
|
|||
token = delta.get("content") or ""
|
||||
if token:
|
||||
yield AIMessageChunk(content=token)
|
||||
await asyncio.sleep(0) # flush immediately
|
||||
|
||||
# Capture usage from final summary chunk
|
||||
if data.get("usage"):
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import json
|
||||
import asyncio
|
||||
from datetime import datetime, UTC
|
||||
from typing import AsyncGenerator
|
||||
|
||||
|
|
@ -71,6 +72,7 @@ async def kia_token_stream(
|
|||
if token:
|
||||
full_ai_content += token
|
||||
yield json.dumps({"content": token}, ensure_ascii=False) + "\n"
|
||||
await asyncio.sleep(0) # flush token to client immediately
|
||||
if chunk.usage_metadata:
|
||||
input_tokens = chunk.usage_metadata.get("input_tokens", 0)
|
||||
output_tokens = chunk.usage_metadata.get("output_tokens", 0)
|
||||
|
|
|
|||
Loading…
Reference in New Issue