[Misc] Added validation for Cohere /v2/embed input field exclusivity (#45640)
Signed-off-by: Taneem Ibrahim <taneem.ibrahim@gmail.com>
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
"""Unit tests for EmbedIOProcessor."""
|
||||
|
||||
import pytest
|
||||
from pydantic import TypeAdapter
|
||||
from pydantic import TypeAdapter, ValidationError
|
||||
|
||||
from vllm import PoolingParams
|
||||
from vllm.entrypoints.pooling.embed.io_processor import EmbedIOProcessor
|
||||
@@ -105,6 +105,59 @@ class TestEmbeddingRequestParsing:
|
||||
assert request.chat_template_kwargs == {"instruction": "Represent the query: "}
|
||||
|
||||
|
||||
class TestCohereEmbedRequestParsing:
|
||||
"""Unit tests for Cohere embed request parsing."""
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"request_body",
|
||||
[
|
||||
{"model": "test"},
|
||||
{"model": "test", "texts": ["hello"], "images": ["image-uri"]},
|
||||
{
|
||||
"model": "test",
|
||||
"texts": ["hello"],
|
||||
"inputs": [
|
||||
{"content": [{"type": "text", "text": "hello"}]},
|
||||
],
|
||||
},
|
||||
{
|
||||
"model": "test",
|
||||
"images": ["image-uri"],
|
||||
"inputs": [
|
||||
{"content": [{"type": "text", "text": "hello"}]},
|
||||
],
|
||||
},
|
||||
{"model": "test", "texts": []},
|
||||
{"model": "test", "images": []},
|
||||
{"model": "test", "inputs": []},
|
||||
],
|
||||
)
|
||||
def test_rejects_invalid_input_field_combinations(self, request_body):
|
||||
with pytest.raises(
|
||||
ValidationError,
|
||||
match="Exactly one of texts, images, or inputs must be provided",
|
||||
):
|
||||
CohereEmbedRequest(**request_body)
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"request_body",
|
||||
[
|
||||
{"model": "test", "texts": ["hello"]},
|
||||
{"model": "test", "images": ["image-uri"]},
|
||||
{
|
||||
"model": "test",
|
||||
"inputs": [
|
||||
{"content": [{"type": "text", "text": "hello"}]},
|
||||
],
|
||||
},
|
||||
],
|
||||
)
|
||||
def test_accepts_exactly_one_non_empty_input_field(self, request_body):
|
||||
request = CohereEmbedRequest(**request_body)
|
||||
|
||||
assert request.model == "test"
|
||||
|
||||
|
||||
class TestResolveTruncation:
|
||||
"""Unit tests for EmbedIOProcessor._resolve_cohere_truncation."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user