Handle empty input string for embedding models (#5621)

Co-authored-by: Ravi Theja Desetty <ravitheja@Ravis-MacBook-Pro.local>
This commit is contained in:
Ravi Theja
2025-05-11 20:47:15 +05:30
committed by GitHub
parent 230106304d
commit 41a645f556
2 changed files with 44 additions and 0 deletions

View File

@@ -676,6 +676,22 @@ class TestOpenAIEmbedding(CustomTestCase):
self.assertTrue(len(response.data[0].embedding) > 0)
self.assertTrue(len(response.data[1].embedding) > 0)
def test_empty_string_embedding(self):
"""Test embedding an empty string."""
client = openai.Client(api_key=self.api_key, base_url=self.base_url)
# Text embedding example with empty string
text = ""
# Expect a BadRequestError for empty input
with self.assertRaises(openai.BadRequestError) as cm:
client.embeddings.create(
model=self.model,
input=text,
)
# check the status code
self.assertEqual(cm.exception.status_code, 400)
class TestOpenAIServerIgnoreEOS(CustomTestCase):
@classmethod