mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-09 03:18:44 +00:00
fix(responses): merge sync completion kwargs to avoid duplicate keys
Double-splatting litellm_completion_request and kwargs raised TypeError when metadata or service_tier were set. Match the async merge pattern. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
56f430ebcc
commit
6a56f6d315
2 changed files with 26 additions and 3 deletions
|
|
@ -58,11 +58,14 @@ class LiteLLMCompletionTransformationHandler:
|
|||
**kwargs,
|
||||
)
|
||||
|
||||
completion_args = {}
|
||||
completion_args.update(kwargs)
|
||||
completion_args.update(litellm_completion_request)
|
||||
|
||||
litellm_completion_response: Union[
|
||||
ModelResponse, litellm.CustomStreamWrapper
|
||||
] = litellm.completion(
|
||||
**litellm_completion_request,
|
||||
**kwargs,
|
||||
**completion_args,
|
||||
)
|
||||
|
||||
if isinstance(litellm_completion_response, ModelResponse):
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import sys
|
|||
import pytest
|
||||
import asyncio
|
||||
from typing import Optional
|
||||
from unittest.mock import patch, AsyncMock
|
||||
from unittest.mock import patch, AsyncMock, MagicMock
|
||||
from litellm.responses.litellm_completion_transformation.handler import (
|
||||
LiteLLMCompletionTransformationHandler,
|
||||
)
|
||||
|
|
@ -130,6 +130,26 @@ def test_multiturn_tool_calls():
|
|||
print("follow_up_response=", follow_up_response)
|
||||
|
||||
|
||||
def test_response_api_handler_merges_metadata_and_service_tier_without_error():
|
||||
"""Sync path must merge kwargs like async; double-splat raises TypeError."""
|
||||
handler = LiteLLMCompletionTransformationHandler()
|
||||
|
||||
with patch("litellm.completion", new_callable=MagicMock) as mock_completion:
|
||||
mock_completion.return_value = ModelResponse(
|
||||
id="id", created=0, model="test", object="chat.completion", choices=[]
|
||||
)
|
||||
handler.response_api_handler(
|
||||
model="test",
|
||||
input="hi",
|
||||
responses_api_request={},
|
||||
metadata={"trace": "abc"},
|
||||
service_tier="auto",
|
||||
)
|
||||
assert mock_completion.call_count == 1
|
||||
assert mock_completion.call_args.kwargs["metadata"] == {"trace": "abc"}
|
||||
assert mock_completion.call_args.kwargs["service_tier"] == "auto"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_async_response_api_handler_merges_trace_id_without_error():
|
||||
handler = LiteLLMCompletionTransformationHandler()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue