mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-15 09:12:18 +00:00
fix(decisions): merge a deployment's extra_body into the forwarded OpenAI Decisions body
This commit is contained in:
parent
61479093dd
commit
2d977e905d
2 changed files with 16 additions and 4 deletions
|
|
@ -109,6 +109,9 @@ _ASSET_ENTRY_ADAPTER: Final[TypeAdapter[tuple[DecisionsAssetReference, Decisions
|
|||
tuple[DecisionsAssetReference, DecisionsAsset]
|
||||
)
|
||||
_FIELDS_ADAPTER: Final[TypeAdapter[Mapping[str, object]]] = TypeAdapter(Mapping[str, object])
|
||||
_EXTRA_BODY_ADAPTER: Final[TypeAdapter[Mapping[str, object] | None]] = TypeAdapter(
|
||||
Mapping[str, object] | None, config=ConfigDict(title="extra_body")
|
||||
)
|
||||
|
||||
|
||||
def _valid_image(image: object) -> DecisionsImage | None:
|
||||
|
|
@ -781,16 +784,23 @@ def _sent_fields(
|
|||
("audio", fields.audio),
|
||||
("videos", fields.videos),
|
||||
)
|
||||
forwarded: Final = filter_out_litellm_params(kwargs=kwargs, excluding=_LITELLM_SETTINGS)
|
||||
sent: Final = MappingProxyType(
|
||||
{
|
||||
**{name: value for name, value in explicit if value is not None},
|
||||
**filter_out_litellm_params(kwargs=kwargs, excluding=_LITELLM_SETTINGS),
|
||||
**{name: value for name, value in forwarded.items() if name != "extra_body"},
|
||||
}
|
||||
)
|
||||
try:
|
||||
return _FIELDS_ADAPTER.validate_python(to_jsonable_python(sent, exclude_none=True, fallback=_plain_mapping))
|
||||
fields_sent: Final = _FIELDS_ADAPTER.validate_python(
|
||||
to_jsonable_python(sent, exclude_none=True, fallback=_plain_mapping)
|
||||
)
|
||||
extra_body: Final = _EXTRA_BODY_ADAPTER.validate_python(
|
||||
to_jsonable_python(forwarded.get("extra_body"), fallback=_plain_mapping)
|
||||
)
|
||||
except (TypeError, ValueError) as error:
|
||||
raise _invalid_request(error, route) from error
|
||||
return MappingProxyType({**fields_sent, **(extra_body or {})})
|
||||
|
||||
|
||||
def _native_body(
|
||||
|
|
|
|||
|
|
@ -4155,6 +4155,7 @@ async def test_an_openai_deployment_behind_a_router_gets_the_caller_body_as_sent
|
|||
"drop_params": True,
|
||||
"timeout": 30,
|
||||
"max_retries": 0,
|
||||
"extra_body": {"service_tier": "flex"},
|
||||
},
|
||||
"model_info": {"id": "luna-deployment"},
|
||||
}
|
||||
|
|
@ -4174,6 +4175,7 @@ async def test_an_openai_deployment_behind_a_router_gets_the_caller_body_as_sent
|
|||
"input": list(_NATIVE_OPENAI_INPUT),
|
||||
"questions": list(_NATIVE_OPENAI_QUESTIONS),
|
||||
**_NATIVE_OPENAI_FIELDS,
|
||||
"service_tier": "flex",
|
||||
}
|
||||
assert response.model_dump(mode="json") == _NATIVE_OPENAI_RESPONSE
|
||||
assert response._hidden_params["custom_llm_provider"] == "openai"
|
||||
|
|
@ -4182,8 +4184,8 @@ async def test_an_openai_deployment_behind_a_router_gets_the_caller_body_as_sent
|
|||
|
||||
@pytest.mark.parametrize(
|
||||
"unsendable",
|
||||
({"prompt_cache_key": object()}, {"prompt_cache_options": {"tag": b"\xff\xfe"}}),
|
||||
ids=("not_json", "not_utf8"),
|
||||
({"prompt_cache_key": object()}, {"prompt_cache_options": {"tag": b"\xff\xfe"}}, {"extra_body": "flex"}),
|
||||
ids=("not_json", "not_utf8", "extra_body_not_an_object"),
|
||||
)
|
||||
@pytest.mark.usefixtures("openai_default_base")
|
||||
def test_a_caller_value_that_cannot_be_sent_as_json_is_a_client_error_before_http(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue