The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
refactor(responses): route function_call added-events through the shared tool-call converter
Tin Chi Lo19c875fa82f3
diff --git a/litellm/completion_extras/litellm_responses_transformation/transformation.py b/litellm/completion_extras/litellm_responses_transformation/transformation.pyindex eb4acb86674..9fd193b4eeb 100644--- a/litellm/completion_extras/litellm_responses_transformation/transformation.py+++ b/litellm/completion_extras/litellm_responses_transformation/transformation.py@@ -120,7 +120,11 @@ def _tool_call_dict_from_output_item(item: dict[str, Any]) -> dict[str, Any]:"type": "function",}provider_specific_fields = item.get("provider_specific_fields")- if isinstance(provider_specific_fields, dict) and provider_specific_fields:+ if provider_specific_fields and not isinstance(provider_specific_fields, dict):+ provider_specific_fields = (+ dict(provider_specific_fields) if hasattr(provider_specific_fields, "__dict__") else None+ )+ if provider_specific_fields:tool_call_dict["provider_specific_fields"] = provider_specific_fieldstool_call_dict["function"]["provider_specific_fields"] = provider_specific_fieldsreturn tool_call_dict@@ -1184,39 +1188,26 @@ class OpenAiResponsesToChatCompletionStreamIterator(BaseModelResponseIterator):elif event_type == "response.output_item.added":# New output item addedoutput_item = parsed_chunk.get("item", {})- if output_item.get("type") == "function_call":- # Extract provider_specific_fields if present- provider_specific_fields = output_item.get("provider_specific_fields")- if provider_specific_fields and not isinstance(provider_specific_fields, dict):- provider_specific_fields = (- dict(provider_specific_fields) if hasattr(provider_specific_fields, "__dict__") else {}- )+ if output_item.get("type") in ("function_call", "custom_tool_call"):+ converted = _tool_call_dict_from_output_item(output_item)+ provider_specific_fields = converted.get("provider_specific_fields")function_chunk = ChatCompletionToolCallFunctionChunk(- name=output_item.get("name", None),- arguments=output_item.get("arguments") or parsed_chunk.get("arguments") or "",+ name=converted["function"]["name"] or None,+ arguments=converted["function"]["arguments"] or parsed_chunk.get("arguments") or "",)-if provider_specific_fields:function_chunk["provider_specific_fields"] = provider_specific_fields- from litellm.responses.litellm_completion_transformation.transformation import (- LiteLLMCompletionResponsesConfig,- )-tool_call_index = OpenAiResponsesToChatCompletionStreamIterator._sequential_tool_call_index(tool_call_index_map, parsed_chunk.get("output_index", 0))tool_call_chunk = ChatCompletionToolCallChunk(- id=LiteLLMCompletionResponsesConfig._tool_call_id_from_responses_item(- output_item.get("id"), output_item.get("call_id")- ),+ id=converted["id"],index=tool_call_index,type="function",function=function_chunk,)-- # Add provider_specific_fields if presentif provider_specific_fields:tool_call_chunk.provider_specific_fields = provider_specific_fields # type: ignore@@ -1229,32 +1220,6 @@ class OpenAiResponsesToChatCompletionStreamIterator(BaseModelResponseIterator):)])- elif output_item.get("type") == "custom_tool_call":- tool_call_index = OpenAiResponsesToChatCompletionStreamIterator._sequential_tool_call_index(- tool_call_index_map, parsed_chunk.get("output_index", 0)- )- converted = _tool_call_dict_from_output_item(output_item)- return ModelResponseStream(- choices=[- StreamingChoices(- index=0,- delta=Delta(- tool_calls=[- ChatCompletionToolCallChunk(- id=converted["id"],- index=tool_call_index,- type="function",- function=ChatCompletionToolCallFunctionChunk(- name=converted["function"]["name"],- arguments=converted["function"]["arguments"],- ),- )- ]- ),- finish_reason=None,- )- ]- )elif event_type in (ResponsesAPIStreamEvents.FUNCTION_CALL_ARGUMENTS_DELTA,ResponsesAPIStreamEvents.CUSTOM_TOOL_CALL_INPUT_DELTA,