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

This commit is contained in:
vahidrezvani 2026-02-25 12:07:00 +03:30
parent d450b318c0
commit 8301329aca
1 changed files with 9 additions and 1 deletions

View File

@ -1,6 +1,7 @@
import os
import json
import math
import asyncio
from uuid import UUID
from datetime import date, datetime, timedelta, UTC
from fastapi import HTTPException
@ -202,7 +203,14 @@ def chatbot_workflow(bot, now):
)
] + trimmed_messages
response = await model.ainvoke(input=input_messages, **kwargs)
# KIA API returns choices=null in streaming chunks which breaks LangChain.
# Even with streaming=False, ainvoke() still uses _astream() internally in async path.
# asyncio.to_thread forces sync model.invoke() which calls the real non-streaming endpoint.
if is_kia:
print(f"[KiaAI] Calling model via asyncio.to_thread (non-streaming) | model='{bot.model}'")
response = await asyncio.to_thread(model.invoke, input_messages)
else:
response = await model.ainvoke(input=input_messages, **kwargs)
if is_kia:
print(f"[KiaAI] Response received | type={type(response).__name__}")