Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion recipe/retool/retool_sft_preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"""

import json
import os
import re
from typing import Any

Expand Down Expand Up @@ -119,6 +120,7 @@ def process(row: dict, *, tools: str):
messages.append(message)
role = "assistant"

tools = json.loads(tools)
return {"messages": messages, "tools": tools}


Expand All @@ -130,4 +132,5 @@ def process(row: dict, *, tools: str):

data = datasets.load_dataset("JoeYing/ReTool-SFT")["train"]
data = data.map(process, fn_kwargs={"tools": tools})
data.to_parquet("wuxibin/ReTool-SFT/data/train-00000-of-00001.parquet")
save_path = os.path.expanduser("~/ReTool-SFT/data/train-00000-of-00001.parquet")
data.to_parquet(save_path)
Comment on lines +135 to +136
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The call to data.to_parquet(save_path) will fail with a FileNotFoundError if the parent directory of save_path (i.e., ~/ReTool-SFT/data/) does not exist. This will cause the script to crash.

To make the script more robust, you should ensure the directory exists before attempting to write the file. I'd suggest replacing these lines with the following to create the directory if it's missing:

    save_path = os.path.expanduser("~/ReTool-SFT/data/train-00000-of-00001.parquet")
    os.makedirs(os.path.dirname(save_path), exist_ok=True)
    data.to_parquet(save_path)