mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-10 03:28:53 +00:00
test(router): add direct coverage for _stream_chunks_have_generated_content
CI's router_code_coverage check flags any router.py function never referenced by name in a test file; the new helper was only exercised indirectly through the mid-stream re-raise guard tests.
This commit is contained in:
parent
c1f126922b
commit
74c24a0a1a
1 changed files with 42 additions and 0 deletions
|
|
@ -6351,6 +6351,48 @@ def test_strip_http_framing_headers_non_dict_headers():
|
|||
assert exc.headers == "not-a-mapping"
|
||||
|
||||
|
||||
def test_stream_chunks_have_generated_content_detects_text_and_non_text():
|
||||
from litellm.router import _stream_chunks_have_generated_content
|
||||
from litellm.types.utils import (
|
||||
ChatCompletionDeltaToolCall,
|
||||
Delta,
|
||||
Function,
|
||||
StreamingChoices,
|
||||
)
|
||||
|
||||
def _chunk(delta):
|
||||
return litellm.ModelResponseStream(
|
||||
id="chatcmpl-1",
|
||||
model="gpt-4",
|
||||
object="chat.completion.chunk",
|
||||
choices=[StreamingChoices(finish_reason=None, index=0, delta=delta)],
|
||||
)
|
||||
|
||||
assert _stream_chunks_have_generated_content([]) is False
|
||||
|
||||
empty_chunk = _chunk(Delta(role="assistant"))
|
||||
assert _stream_chunks_have_generated_content([empty_chunk]) is False
|
||||
|
||||
text_chunk = _chunk(Delta(content="Hello"))
|
||||
assert _stream_chunks_have_generated_content([text_chunk]) is True
|
||||
|
||||
reasoning_chunk = _chunk(Delta(reasoning_content="Thinking"))
|
||||
assert _stream_chunks_have_generated_content([reasoning_chunk]) is True
|
||||
|
||||
tool_call_delta = Delta(
|
||||
tool_calls=[
|
||||
ChatCompletionDeltaToolCall(
|
||||
id="call_1",
|
||||
function=Function(name="get_weather", arguments="{}"),
|
||||
type="function",
|
||||
index=0,
|
||||
)
|
||||
]
|
||||
)
|
||||
tool_call_chunk = _chunk(tool_call_delta)
|
||||
assert _stream_chunks_have_generated_content([tool_call_chunk]) is True
|
||||
|
||||
|
||||
def test_get_configured_token_limits_reads_deployment_model_info():
|
||||
router = litellm.Router(
|
||||
model_list=[
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue