Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions tests/ut/tools/test_send_request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project

import pytest

from tools.send_request import validate_response


@pytest.mark.parametrize("expected", [{}, None], ids=["empty", "missing"])
def test_validate_response_enforces_model_length_without_token_expectations(expected: dict[str, int] | None) -> None:
response = {"usage": {"prompt_tokens": 10, "completion_tokens": 5}}

validate_response(response, expected)
validate_response(response, expected, max_model_len=15)
with pytest.raises(AssertionError, match=r"total_tokens \(15\) exceeds max_model_len \(12\)"):
validate_response(response, expected, max_model_len=12)
3 changes: 1 addition & 2 deletions tools/send_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@ def validate_response(response_json: dict, expected: dict | None, max_model_len:

print(f"Token usage - prompt: {prompt_tokens}, completion: {completion_tokens}, total: {total_tokens}")

if not expected:
return
expected = expected or {}

if "prompt_tokens" in expected:
expected_prompt_tokens = expected["prompt_tokens"]
Expand Down
Loading