mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-12 03:48:56 +00:00
fix(decisions): return guardrail_information on OpenAI-format decisions when requested
Backport of the #45184 and #45214 guardrail fix. Cherry-picked from855f0bb765(litellm_systemone_endpoint) as merged into #45214 atc19ada66ed(litellm_openai_decisions_provider).
This commit is contained in:
parent
f0cb1d5757
commit
7446e02690
2 changed files with 24 additions and 1 deletions
|
|
@ -313,7 +313,7 @@ class OpenAIDecisionResponse(_HiddenParamsResponse):
|
|||
answers: tuple[OpenAIDecisionAnswer, ...]
|
||||
usage: OpenAIDecisionUsage
|
||||
|
||||
model_config = ConfigDict(frozen=True)
|
||||
model_config = ConfigDict(extra="allow", frozen=True)
|
||||
|
||||
|
||||
_NO_EXTRA: Final[Mapping[str, object]] = MappingProxyType({})
|
||||
|
|
|
|||
|
|
@ -386,6 +386,29 @@ def test_openai_format_decisions_translate_through_systemone(
|
|||
assert float(response.headers["x-litellm-response-cost"]) > 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("endpoint", "request_body", "upstream_response"),
|
||||
(
|
||||
("/v1/systemone", _REQUEST, _RESPONSE),
|
||||
("/v1/decisions", _OPENAI_FORMAT_REQUEST, _SYSTEMONE_ANSWERS_FOR_OPENAI_REQUEST),
|
||||
),
|
||||
ids=("systemone", "openai_format"),
|
||||
)
|
||||
def test_decisions_return_guardrail_information_when_requested(
|
||||
client: TestClient,
|
||||
respx_mock: respx.MockRouter,
|
||||
endpoint: str,
|
||||
request_body: Mapping[str, object],
|
||||
upstream_response: Mapping[str, object],
|
||||
) -> None:
|
||||
respx_mock.post("https://api.perplexity.ai/v1/decisions").respond(json=upstream_response)
|
||||
|
||||
response: Final = client.post(endpoint, json={**request_body, "include_guardrail_response": True})
|
||||
|
||||
assert response.status_code == 200, response.text
|
||||
assert response.json()["guardrail_information"] == []
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"request_body",
|
||||
(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue