File size: 2,807 Bytes
70a7f67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import json

# with open("/mnt/general/wanghy/RAGEN/runs/Game2048NoisyDQN__noisy_dqn_2048_refined__1__1765041200/sft/step_300000_sft_singleturn_slidewindows5_7000score.json") as f:
#     dataset1 = json.load(f)

with open("/mnt/general/wanghy/RAGEN/runs/BanditDQN__dqn_bandit_nochangeenv__1__1764233298/sft/step_50000_sft.json") as f:
    dataset2 = json.load(f)

with open("/mnt/general/wanghy/RAGEN/runs/RubiksCube2x2__ppo_rubikscube1_1218/sft/step_999424_sft_singleturn.json") as f:
    dataset3 = json.load(f)

with open("/mnt/general/wanghy/RAGEN/runs/RubiksCube2x2__ppo_rubikscube2_1219_turn5/sft/step_999424_sft_singleturn.json") as f:
    dataset4 = json.load(f)

with open("/mnt/general/wanghy/RAGEN/runs/RubiksCube2x2__ppo_rubikscube3_1219_turn5_6000/sft/step_999424_sft_singleturn.json") as f:
    dataset5 = json.load(f)

with open("/mnt/general/wanghy/RAGEN/runs/FrozenLake__ppo_frozenlake_nochangeenv__p0.9_slippery/sft/step_1986560_sft_slippery_singleturn.json") as f:
    dataset6 = json.load(f)

with open("/mnt/general/wanghy/RAGEN/runs/SokobanNoisyDQN__noisy_dqn_sokoban__1__1764155447/sft/step_1000000_sft_singleturn.json") as f:
    dataset7 = json.load(f)

with open("/mnt/general/wanghy/RAGEN/runs/SokobanNoisyDQN__noisy_dqn_sokoban__1__1764155464/sft/step_1000000_sft_singleturn.json") as f:
    dataset8 = json.load(f)

with open("/mnt/general/wanghy/RAGEN/runs/Sudoku__ppo_sudoku_actionmask__4x4/sft/step_999424_sft_singleturn_nohint.json") as f:
    dataset9 = json.load(f)


data = dataset2 +dataset3 +dataset4 +dataset5 +dataset6 +dataset7 +dataset8 +dataset9

target_user_str = " <think> [Your thoughts] </think>" 
target_assistant_str1 = "<think></think>"
target_assistant_str2 = "<think> </think>"

# 2. 遍历数据并进行替换
# 假设 data 是一个列表,列表里每个元素都有 "messages" 字段
if isinstance(data, list):
    for entry in data:
        if "messages" in entry:
            for msg in entry["messages"]:
                role = msg.get("role")
                content = msg.get("content", "")
                
                # 处理 User
                if role == "user":
                    if target_user_str in content:
                        msg["content"] = content.replace(target_user_str, "")
                
                # 处理 Assistant
                elif role == "assistant":
                    if (target_assistant_str1 in content) or (target_assistant_str2 in content):
                        msg["content"] = content.replace(target_assistant_str1, "").replace(target_assistant_str2, "")
import pdb;pdb.set_trace()
# 3. 将修改后的数据保存为新文件
with open("/mnt/general/wanghy/RAGEN/runs/multitask_nothink/sft_no2048.json", 'w', encoding='utf-8') as f:
    json.dump(data, f, ensure_ascii=False, indent=2)