[Bugfix] Raise VLLMValidationError for non-integer logit_bias keys (#46612)
Signed-off-by: muhammadfawaz1 <135441198+muhammadfawaz1@users.noreply.github.com> Co-authored-by: Mahad Durrani <114791389+mahadrehmann@users.noreply.github.com>
This commit is contained in:
co-authored by
Mahad Durrani
parent
4236514098
commit
97b5ce5c39
@@ -76,3 +76,60 @@ async def test_chat_logit_bias_invalid(client):
|
||||
assert error.status_code == 400
|
||||
assert str(invalid_token_id) in error_message
|
||||
assert str(vocab_size) in error_message
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_chat_logit_bias_non_integer_key(client):
|
||||
"""Test that a non-integer logit_bias key is rejected with a clean,
|
||||
informative error instead of a raw 'invalid literal for int()' message."""
|
||||
with pytest.raises(openai.BadRequestError) as excinfo:
|
||||
await client.chat.completions.create(
|
||||
model=MODEL_NAME,
|
||||
messages=[{"role": "user", "content": "Testing invalid logit bias key"}],
|
||||
max_tokens=5,
|
||||
logit_bias={"not_a_token_id": 50},
|
||||
)
|
||||
|
||||
error = excinfo.value
|
||||
error_message = str(error)
|
||||
|
||||
assert error.status_code == 400
|
||||
assert "not_a_token_id" in error_message
|
||||
assert "logit_bias" in error_message
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_chat_logit_bias_non_numeric_value(client):
|
||||
"""Test that a non-numeric logit_bias value is rejected with a message
|
||||
that names the specific offending token, not just a generic TypeError."""
|
||||
with pytest.raises(openai.BadRequestError) as excinfo:
|
||||
await client.chat.completions.create(
|
||||
model=MODEL_NAME,
|
||||
messages=[{"role": "user", "content": "Testing invalid logit bias value"}],
|
||||
max_tokens=5,
|
||||
logit_bias={"1": "not_a_number"},
|
||||
)
|
||||
|
||||
error = excinfo.value
|
||||
error_message = str(error)
|
||||
|
||||
assert error.status_code == 400
|
||||
assert "logit_bias" in error_message
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_chat_logit_bias_multiple_non_integer_keys(client):
|
||||
"""Test that ALL invalid logit_bias keys are reported together,
|
||||
not just the first one encountered."""
|
||||
with pytest.raises(openai.BadRequestError) as excinfo:
|
||||
await client.chat.completions.create(
|
||||
model=MODEL_NAME,
|
||||
messages=[{"role": "user", "content": "Testing multiple bad keys"}],
|
||||
max_tokens=5,
|
||||
logit_bias={"bad1": 50.0, "bad2": 20.0},
|
||||
)
|
||||
|
||||
error_message = str(excinfo.value)
|
||||
assert excinfo.value.status_code == 400
|
||||
assert "bad1" in error_message
|
||||
assert "bad2" in error_message
|
||||
|
||||
Reference in New Issue
Block a user