Skip to content

Commit 5cd3742

Browse files
authored
Merge pull request #229 from togethercomputer/artem/fix-empty-messages
Fix empty messages
2 parents 298901e + ac770fb commit 5cd3742

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ build-backend = "poetry.masonry.api"
1212

1313
[tool.poetry]
1414
name = "together"
15-
version = "1.3.10"
15+
version = "1.3.11"
1616
authors = [
1717
"Together AI <[email protected]>"
1818
]

src/together/utils/files.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,14 @@ def _check_jsonl(file: Path) -> Dict[str, Any]:
177177
error_source="key_value",
178178
)
179179

180+
if len(json_line[message_column]) == 0:
181+
raise InvalidFileFormatError(
182+
message=f"Invalid format on line {idx + 1} of the input file. "
183+
f"Expected a non-empty list of messages. Found empty list",
184+
line_number=idx + 1,
185+
error_source="key_value",
186+
)
187+
180188
for turn_id, turn in enumerate(json_line[message_column]):
181189
if not isinstance(turn, dict):
182190
raise InvalidFileFormatError(

tests/unit/test_files_checks.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,3 +290,16 @@ def test_check_jsonl_extra_column(tmp_path: Path):
290290
report = check_file(file)
291291
assert not report["is_check_passed"]
292292
assert "Found extra column" in report["message"]
293+
294+
295+
def test_check_jsonl_empty_messages(tmp_path: Path):
296+
file = tmp_path / "empty_messages.jsonl"
297+
content = [{"messages": []}]
298+
with file.open("w") as f:
299+
f.write("\n".join(json.dumps(item) for item in content))
300+
301+
report = check_file(file)
302+
assert not report["is_check_passed"]
303+
assert (
304+
"Expected a non-empty list of messages. Found empty list" in report["message"]
305+
)

0 commit comments

Comments
 (0)