From 8301329aca4476acc6a1105b3da4ee5f5d418b9b Mon Sep 17 00:00:00 2001 From: vahidrezvani Date: Wed, 25 Feb 2026 12:07:00 +0330 Subject: [PATCH] add kia ai chat tools 2 --- src/services/chatbot.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/services/chatbot.py b/src/services/chatbot.py index ca9d733..d113080 100644 --- a/src/services/chatbot.py +++ b/src/services/chatbot.py @@ -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__}")