mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-09 03:18:44 +00:00
fix(snowflake): add streaming chunk parser to handle tool_calls in streaming responses (closes #30762)
This commit is contained in:
parent
5699a06413
commit
3aa56759bf
1 changed files with 32 additions and 2 deletions
|
|
@ -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", ""),
|
||||
},
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue