From a8164d35f715c6855b2f222807bf8f88c4340858 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Mon, 23 Mar 2026 12:49:57 +0800 Subject: [PATCH 1/2] fix: cannot use tools in siliconflow provider --- astrbot/core/provider/sources/openai_source.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/astrbot/core/provider/sources/openai_source.py b/astrbot/core/provider/sources/openai_source.py index 73f22925a1..cef62f8a09 100644 --- a/astrbot/core/provider/sources/openai_source.py +++ b/astrbot/core/provider/sources/openai_source.py @@ -329,14 +329,20 @@ async def _query_stream( state = ChatCompletionStreamState() async for chunk in stream: + choice = chunk.choices[0] + delta = choice.delta + + # siliconflow workaround + if dtcs := delta.tool_calls: + for tc in dtcs: + if tc.function and tc.function.arguments: + tc.type = "function" try: state.handle_chunk(chunk) except Exception as e: - logger.warning("Saving chunk state error: " + str(e)) + logger.error("Saving chunk state error: " + str(e)) if not chunk.choices: continue - choice = chunk.choices[0] - delta = choice.delta # logger.debug(f"chunk delta: {delta}") # handle the content delta reasoning = self._extract_reasoning_content(chunk) From 3e7001c6ea38062cfd105ce60aa2c5a2f7e0ed47 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Mon, 23 Mar 2026 12:53:17 +0800 Subject: [PATCH 2/2] fix: handle empty choices in ChatCompletionStreamState --- astrbot/core/provider/sources/openai_source.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/astrbot/core/provider/sources/openai_source.py b/astrbot/core/provider/sources/openai_source.py index cef62f8a09..d64feb5a07 100644 --- a/astrbot/core/provider/sources/openai_source.py +++ b/astrbot/core/provider/sources/openai_source.py @@ -329,6 +329,8 @@ async def _query_stream( state = ChatCompletionStreamState() async for chunk in stream: + if not chunk.choices: + continue choice = chunk.choices[0] delta = choice.delta @@ -341,8 +343,6 @@ async def _query_stream( state.handle_chunk(chunk) except Exception as e: logger.error("Saving chunk state error: " + str(e)) - if not chunk.choices: - continue # logger.debug(f"chunk delta: {delta}") # handle the content delta reasoning = self._extract_reasoning_content(chunk)