From 3aa56759bfea04ebc5665f2203ad9633fcce3fba Mon Sep 17 00:00:00 2001 From: botbikamordehai2-sketch Date: Sun, 21 Jun 2026 11:59:19 +0000 Subject: [PATCH] fix(snowflake): add streaming chunk parser to handle tool_calls in streaming responses (closes #30762) --- litellm/llms/snowflake/common_utils.py | 34 ++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/litellm/llms/snowflake/common_utils.py b/litellm/llms/snowflake/common_utils.py index 40c8270f95f..fd3e48e4703 100644 --- a/litellm/llms/snowflake/common_utils.py +++ b/litellm/llms/snowflake/common_utils.py @@ -1,7 +1,8 @@ -from typing import Optional +from typing import Optional, Iterator, Dict, Any +from litellm.llms.base_llm.chat.transformation import BaseConfig -class SnowflakeBase: +class SnowflakeBase(BaseConfig): def validate_environment( self, headers: dict, @@ -32,3 +33,32 @@ class SnowflakeBase: } ) return headers + + def chunk_parser(self, chunk: Dict[str, Any]) -> Iterator[Dict[str, Any]]: + """Parse Snowflake streaming chunks to emit OpenAI-style delta.""" + # Snowflake streaming returns events with data: {"type": "delta", ...} + # or {"type": "tool_use", ...} + if "type" not in chunk: + return + if chunk["type"] == "delta": + yield {"choices": [{"delta": {"content": chunk.get("delta", "")}}]} + elif chunk["type"] == "tool_use": + # Snowflake tool_use format: {"type": "tool_use", "name": ..., "input": ...} + yield { + "choices": [ + { + "delta": { + "tool_calls": [ + { + "index": 0, + "id": None, + "function": { + "name": chunk.get("name", ""), + "arguments": chunk.get("input", ""), + }, + } + ] + } + } + ] + }