fix(snowflake): add streaming chunk parser to handle tool_calls in streaming responses (closes #30762)

This commit is contained in:
botbikamordehai2-sketch 2026-06-21 11:59:19 +00:00
parent 5699a06413
commit 3aa56759bf

View file

@ -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", ""),
},
}
]
}
}
]
}