Skip to content

Commit 72d9344

Browse files
committed
Allow uploading tool calling datasets
1 parent 2d7b835 commit 72d9344

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

src/together/lib/cli/api/_utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ def wrapper(*args: Any, **kwargs: Any) -> Any:
160160
except Exception as e:
161161
click.echo(prefix_styled + click.style("Failed", fg="red"))
162162
click.echo(prefix_styled + click.style(f"An unexpected error occurred - {str(e)}", fg="red"))
163+
import traceback
164+
165+
click.echo(prefix_styled + click.style("Traceback:", fg="red"))
166+
click.echo(prefix_styled + click.style(traceback.format_exc(), fg="red"))
163167
sys.exit(1)
164168

165169
return wrapper # type: ignore

src/together/lib/constants.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,11 @@ class DatasetFormat(enum.Enum):
6666
"non_preferred_output",
6767
],
6868
}
69-
REQUIRED_COLUMNS_MESSAGE = ["role", "content"]
69+
JSONL_ADDITIONAL_COLUMNS_MAP = {
70+
DatasetFormat.GENERAL: [],
71+
DatasetFormat.CONVERSATION: ["tools"],
72+
DatasetFormat.INSTRUCTION: [],
73+
DatasetFormat.PREFERENCE_OPENAI: [],
74+
}
75+
REQUIRED_COLUMNS_MESSAGE = ["role"]
7076
POSSIBLE_ROLES_CONVERSATION = ["system", "user", "assistant"]

src/together/lib/utils/files.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
REQUIRED_COLUMNS_MESSAGE,
2323
JSONL_REQUIRED_COLUMNS_MAP,
2424
POSSIBLE_ROLES_CONVERSATION,
25+
JSONL_ADDITIONAL_COLUMNS_MAP,
2526
DatasetFormat,
2627
)
2728

@@ -392,7 +393,14 @@ def validate_messages(
392393
message_weight = _check_message_weight(message, idx)
393394
previous_role = _check_message_role(message, previous_role, idx)
394395
assistant_role_exists |= previous_role == "assistant"
395-
is_multimodal, number_of_images = _check_message_content(message["content"], role=previous_role, idx=idx)
396+
397+
number_of_images = 0
398+
is_multimodal = False
399+
400+
content = message.get("content")
401+
if content is not None:
402+
is_multimodal, number_of_images = _check_message_content(content, role=previous_role, idx=idx)
403+
396404
# Multimodal validation
397405
if number_of_images > 0 and message_weight is not None and message_weight != 0:
398406
raise InvalidFileFormatError(
@@ -656,7 +664,11 @@ def _check_jsonl(file: Path, purpose: FilePurpose | str) -> Dict[str, Any]:
656664

657665
# Check that there are no extra columns
658666
for column in cast(List[str], json_line.keys()):
659-
if column not in JSONL_REQUIRED_COLUMNS_MAP[possible_format]:
667+
allowed_columns = (
668+
JSONL_REQUIRED_COLUMNS_MAP[possible_format]
669+
+ JSONL_ADDITIONAL_COLUMNS_MAP[possible_format]
670+
)
671+
if column not in allowed_columns:
660672
raise InvalidFileFormatError(
661673
message=f'Found extra column "{column}" in the line {idx + 1}.',
662674
line_number=idx + 1,

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)