Skip to content

Commit de79b7b

Browse files
committed
explicitly handle null values in text batcher
1 parent 7340cd8 commit de79b7b

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

inference/utils/batch.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,19 @@ def prepare_url_data(self, url) -> URLData:
2424
"""Prepare single URL data for API"""
2525
return {
2626
"url_id": url.id,
27-
"text": url.scraped_text,
28-
"metadata": {"title": url.scraped_title, "url": url.url},
27+
"text": url.scraped_text or "", # Handle None values safely
28+
"metadata": {"title": url.scraped_title or "", "url": url.url},
2929
}
3030

3131
def get_text_length(self, url_data: URLData) -> int:
3232
"""Get the length of text content for a URL"""
33-
return len(url_data["text"])
33+
text = url_data["text"]
34+
return len(text) if text is not None else 0
3435

3536
def truncate_oversized_url(self, url_data: URLData) -> URLData:
3637
"""Handle a URL that exceeds the maximum batch length"""
37-
return {**url_data, "text": url_data["text"][: self.max_batch_text_length]}
38+
text = url_data["text"] or ""
39+
return {**url_data, "text": text[: self.max_batch_text_length]}
3840

3941
def would_exceed_batch_limit(self, current_length: int, new_length: int) -> bool:
4042
"""Check if adding new text would exceed batch limit"""

0 commit comments

Comments
 (0)