Add the validation for empty texts.
This commit is contained in:
@@ -27,18 +27,45 @@ def validate_single_or_batch(text: Optional[str], texts: Optional[List[str]]):
|
||||
}
|
||||
)
|
||||
|
||||
if text == "" and texts is None:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail={
|
||||
"error": {
|
||||
"code": "INVALID_INPUT",
|
||||
"message": "'text' cannot be empty or only whitespace",
|
||||
"details": {}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
if texts is not None and len(texts) == 0:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail={
|
||||
"error": {
|
||||
"code": "INVALID_INPUT",
|
||||
"message": "texts list cannot be empty",
|
||||
"message": "Texts list cannot be empty",
|
||||
"details": {}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
if texts is not None and len(texts) != 0:
|
||||
# Check for empty strings within the list
|
||||
for i, t in enumerate(texts):
|
||||
if not isinstance(t, str) or not t.strip():
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail={
|
||||
"error": {
|
||||
"code": "INVALID_INPUT",
|
||||
"message": f"Text item at index {i} in 'texts' cannot be empty or only whitespace",
|
||||
"details": {}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
return text if text is not None else texts
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user