From b7e8b335a76064bba95ed53044abdf8dcd331258 Mon Sep 17 00:00:00 2001 From: Soulter <37870767+Soulter@users.noreply.github.com> Date: Mon, 23 Mar 2026 12:53:37 +0800 Subject: [PATCH] fix: cannot use tools in siliconflow provider (#6829) * fix: cannot use tools in siliconflow provider * fix: handle empty choices in ChatCompletionStreamState --- astrbot/core/provider/sources/openai_source.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/astrbot/core/provider/sources/openai_source.py b/astrbot/core/provider/sources/openai_source.py index 73f22925a..d64feb5a0 100644 --- a/astrbot/core/provider/sources/openai_source.py +++ b/astrbot/core/provider/sources/openai_source.py @@ -329,14 +329,20 @@ class ProviderOpenAIOfficial(Provider): state = ChatCompletionStreamState() async for chunk in stream: - try: - state.handle_chunk(chunk) - except Exception as e: - logger.warning("Saving chunk state error: " + str(e)) if not chunk.choices: continue 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.error("Saving chunk state error: " + str(e)) # logger.debug(f"chunk delta: {delta}") # handle the content delta reasoning = self._extract_reasoning_content(chunk)