mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-13 08:52:02 +00:00
fix(proxy): keep the fallback metadata id on the Responses event and omit an empty model
This commit is contained in:
parent
756d4df1cd
commit
ac770474f4
2 changed files with 11 additions and 6 deletions
|
|
@ -9907,6 +9907,7 @@ def _get_streaming_fallback_metadata(
|
|||
return True, None, fallback_errors
|
||||
|
||||
|
||||
_FALLBACK_METADATA_ID: Final = "litellm-fallback-metadata"
|
||||
_RESPONSES_FALLBACK_METADATA_EVENT_TYPE: Final = "litellm.fallback_metadata"
|
||||
|
||||
|
||||
|
|
@ -9920,13 +9921,14 @@ def _format_fallback_metadata_sse_event(
|
|||
if error_state is not None:
|
||||
event: Final = {
|
||||
"type": _RESPONSES_FALLBACK_METADATA_EVENT_TYPE,
|
||||
"model": fallback_model or "",
|
||||
"id": _FALLBACK_METADATA_ID,
|
||||
**({"model": fallback_model} if fallback_model else {}),
|
||||
"litellm_fallback": litellm_fallback,
|
||||
}
|
||||
error_state.observe_chunk(event)
|
||||
return error_state.mark_emitted(f"data: {json.dumps(event)}\n\n")
|
||||
payload: Final = {
|
||||
"id": "litellm-fallback-metadata",
|
||||
"id": _FALLBACK_METADATA_ID,
|
||||
"object": "chat.completion.chunk",
|
||||
"created": int(time.time()),
|
||||
"model": fallback_model or "",
|
||||
|
|
|
|||
|
|
@ -896,8 +896,10 @@ async def test_chat_stream_sends_fallback_metadata_in_place_of_a_stripped_usage_
|
|||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize("fallback_model", ["fallback-model", None])
|
||||
async def test_responses_stream_sends_fallback_metadata_as_a_typed_event_framed_like_its_neighbours(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
fallback_model: str | None,
|
||||
) -> None:
|
||||
_patch_logging_flags(monkeypatch)
|
||||
monkeypatch.setitem(ps.general_settings, "expose_fallback_errors_to_caller", True)
|
||||
|
|
@ -922,7 +924,7 @@ async def test_responses_stream_sends_fallback_metadata_as_a_typed_event_framed_
|
|||
hidden_params={
|
||||
"additional_headers": {
|
||||
"x-litellm-attempted-fallbacks": 1,
|
||||
"x-litellm-model-group": "fallback-model",
|
||||
**({"x-litellm-model-group": fallback_model} if fallback_model else {}),
|
||||
"x-litellm-fallback-errors": json.dumps(fallback_errors),
|
||||
}
|
||||
},
|
||||
|
|
@ -952,10 +954,11 @@ async def test_responses_stream_sends_fallback_metadata_as_a_typed_event_framed_
|
|||
)
|
||||
assert payloads[1] == {
|
||||
"type": "litellm.fallback_metadata",
|
||||
"model": "fallback-model",
|
||||
"litellm_fallback": {"fallback_model": "fallback-model", "errors": fallback_errors},
|
||||
"id": "litellm-fallback-metadata",
|
||||
**({"model": fallback_model} if fallback_model else {}),
|
||||
"litellm_fallback": {"fallback_model": fallback_model, "errors": fallback_errors},
|
||||
}
|
||||
assert {payload.get("model") for payload in payloads} == {"fallback-model"}
|
||||
assert {payload.get("model") for payload in payloads} == {fallback_model}
|
||||
assert len({frame.startswith("event: ") for frame in event_frames}) == 1
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue