mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-29 01:42:19 +00:00
Merge 8ecd31d76c into 2dccc0dc79
This commit is contained in:
commit
cd295525a8
2 changed files with 9 additions and 2 deletions
|
|
@ -891,7 +891,9 @@ class HeadroomGuardrail(CustomGuardrail):
|
|||
if not has_headroom_retrieve_tool(effective.get("tools")):
|
||||
return base_result
|
||||
return { # mutable-ok: the hook contract is a plain dict the router merges into the request kwargs
|
||||
**effective,
|
||||
**{ # mutable-ok: removes stream-only options
|
||||
key: value for key, value in effective.items() if key != "stream_options"
|
||||
},
|
||||
"stream": False,
|
||||
HEADROOM_CONVERTED_STREAM_KEY: True,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2155,7 +2155,7 @@ async def test_pre_call_deployment_hook_converts_stream_only_for_ccr_chat_comple
|
|||
tools: Optional[list],
|
||||
expect_conversion: bool,
|
||||
):
|
||||
kwargs = {"model": "gpt-4o", "stream": stream, "tools": tools}
|
||||
kwargs = {"model": "gpt-4o", "stream": stream, "stream_options": {"include_usage": True}, "tools": tools}
|
||||
|
||||
result = await guardrail.async_pre_call_deployment_hook(kwargs=kwargs, call_type=call_type)
|
||||
|
||||
|
|
@ -2163,12 +2163,15 @@ async def test_pre_call_deployment_hook_converts_stream_only_for_ccr_chat_comple
|
|||
assert result is kwargs
|
||||
assert HEADROOM_CONVERTED_STREAM_KEY not in kwargs
|
||||
assert kwargs["stream"] is stream
|
||||
assert kwargs["stream_options"] == {"include_usage": True}
|
||||
return
|
||||
|
||||
assert result is not None
|
||||
assert result["stream"] is False
|
||||
assert "stream_options" not in result
|
||||
assert result[HEADROOM_CONVERTED_STREAM_KEY] is True
|
||||
assert kwargs["stream"] is True
|
||||
assert kwargs["stream_options"] == {"include_usage": True}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
|
@ -2223,6 +2226,7 @@ async def test_pre_call_deployment_hook_converts_stream_after_deployment_level_c
|
|||
"model": "gpt-4o",
|
||||
"messages": [dict(m) for m in ORIGINAL_MESSAGES],
|
||||
"stream": True,
|
||||
"stream_options": {"include_usage": True},
|
||||
"guardrails": ["headroom"],
|
||||
"metadata": {},
|
||||
}
|
||||
|
|
@ -2238,6 +2242,7 @@ async def test_pre_call_deployment_hook_converts_stream_after_deployment_level_c
|
|||
assert result is not None
|
||||
assert has_headroom_retrieve_tool(result["tools"])
|
||||
assert result["stream"] is False
|
||||
assert "stream_options" not in result
|
||||
assert result[HEADROOM_CONVERTED_STREAM_KEY] is True
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue