mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-10 03:28:53 +00:00
Bug Fix - responses api fix got multiple values for keyword argument 'litellm_trace_id' (#12225)
* fix - handling trace id arg on responses api * test_async_response_api_handler_merges_trace_id_without_error * test_anthropic_with_responses_api
This commit is contained in:
parent
a6527e5010
commit
4e7115bc34
4 changed files with 54 additions and 6 deletions
|
|
@ -1,8 +1,7 @@
|
|||
model_list:
|
||||
- model_name: groq/*
|
||||
- model_name: anthropic/*
|
||||
litellm_params:
|
||||
model: groq/*
|
||||
api_key: bad
|
||||
model: anthropic/*
|
||||
- model_name: openai/*
|
||||
litellm_params:
|
||||
model: openai/*
|
||||
|
|
|
|||
|
|
@ -56,6 +56,10 @@ class LiteLLMCompletionTransformationHandler:
|
|||
responses_api_request=responses_api_request,
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
completion_args = {}
|
||||
completion_args.update(kwargs)
|
||||
completion_args.update(litellm_completion_request)
|
||||
|
||||
litellm_completion_response: Union[
|
||||
ModelResponse, litellm.CustomStreamWrapper
|
||||
|
|
@ -98,12 +102,15 @@ class LiteLLMCompletionTransformationHandler:
|
|||
previous_response_id=previous_response_id,
|
||||
litellm_completion_request=litellm_completion_request,
|
||||
)
|
||||
|
||||
acompletion_args = {}
|
||||
acompletion_args.update(kwargs)
|
||||
acompletion_args.update(litellm_completion_request)
|
||||
|
||||
litellm_completion_response: Union[
|
||||
ModelResponse, litellm.CustomStreamWrapper
|
||||
] = await litellm.acompletion(
|
||||
**litellm_completion_request,
|
||||
**kwargs,
|
||||
**acompletion_args,
|
||||
)
|
||||
|
||||
if isinstance(litellm_completion_response, ModelResponse):
|
||||
|
|
|
|||
|
|
@ -4,6 +4,10 @@ import pytest
|
|||
import asyncio
|
||||
from typing import Optional
|
||||
from unittest.mock import patch, AsyncMock
|
||||
from litellm.responses.litellm_completion_transformation.handler import LiteLLMCompletionTransformationHandler
|
||||
from litellm.responses.litellm_completion_transformation.transformation import LiteLLMCompletionResponsesConfig
|
||||
from litellm.types.utils import ModelResponse
|
||||
|
||||
|
||||
sys.path.insert(0, os.path.abspath("../.."))
|
||||
import litellm
|
||||
|
|
@ -103,4 +107,33 @@ def test_multiturn_tool_calls():
|
|||
print("follow_up_response=", follow_up_response)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_async_response_api_handler_merges_trace_id_without_error():
|
||||
handler = LiteLLMCompletionTransformationHandler()
|
||||
|
||||
async def fake_session_handler(previous_response_id, litellm_completion_request):
|
||||
litellm_completion_request["litellm_trace_id"] = "session-trace"
|
||||
return litellm_completion_request
|
||||
|
||||
with patch.object(
|
||||
LiteLLMCompletionResponsesConfig,
|
||||
"async_responses_api_session_handler",
|
||||
side_effect=fake_session_handler,
|
||||
):
|
||||
with patch("litellm.acompletion", new_callable=AsyncMock) as mock_acompletion:
|
||||
mock_acompletion.return_value = ModelResponse(
|
||||
id="id", created=0, model="test", object="chat.completion", choices=[]
|
||||
)
|
||||
await handler.async_response_api_handler(
|
||||
litellm_completion_request={"model": "test"},
|
||||
request_input="hi",
|
||||
responses_api_request={"previous_response_id": "123"},
|
||||
litellm_trace_id="original-trace",
|
||||
)
|
||||
# ensure acompletion called once with merged trace_id
|
||||
assert mock_acompletion.call_count == 1
|
||||
assert (
|
||||
mock_acompletion.call_args.kwargs["litellm_trace_id"] == "session-trace"
|
||||
)
|
||||
|
|
@ -119,3 +119,12 @@ def test_bad_request_bad_param_error():
|
|||
client.responses.create(
|
||||
model="gpt-4o", input="This should fail", temperature=2000
|
||||
)
|
||||
|
||||
def test_anthropic_with_responses_api():
|
||||
client = get_test_client()
|
||||
response = client.responses.create(
|
||||
model="anthropic/claude-3-5-sonnet-20240620",
|
||||
input="just respond with the word 'ping'",
|
||||
previous_response_id="hi",
|
||||
)
|
||||
print("anthropic response=", response)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue