fix: traj.jsonl 写入统一使用 UTF-8 编码并保留非 ASCII 字符
所有 run_single_example 变体的 traj.jsonl 写入均加上 encoding="utf-8" 和 ensure_ascii=False,避免中文等字符被转义或写入失败。 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -58,7 +58,7 @@ def run_single_example(agent, env, example, max_steps, instruction, args, exampl
|
||||
with open(os.path.join(example_result_dir, f"step_{step_idx + 1}_{action_timestamp}.png"),
|
||||
"wb") as _f:
|
||||
_f.write(obs['screenshot'])
|
||||
with open(os.path.join(example_result_dir, "traj.jsonl"), "a") as f:
|
||||
with open(os.path.join(example_result_dir, "traj.jsonl"), "a", encoding="utf-8") as f:
|
||||
f.write(json.dumps({
|
||||
"step_num": step_idx + 1,
|
||||
"action_timestamp": action_timestamp,
|
||||
@@ -69,7 +69,7 @@ def run_single_example(agent, env, example, max_steps, instruction, args, exampl
|
||||
"info": info,
|
||||
"screenshot_file": f"step_{step_idx + 1}_{action_timestamp}.png",
|
||||
"a11y_tree": obs.get("accessibility_tree") if isinstance(obs, dict) else None
|
||||
}))
|
||||
}, ensure_ascii=False))
|
||||
f.write("\n")
|
||||
if done:
|
||||
logger.info("The episode is done.")
|
||||
@@ -105,11 +105,11 @@ def run_single_example_human(env, example, max_steps, instruction, args, example
|
||||
_f.write(obs['screenshot'])
|
||||
|
||||
# Save trajectory information
|
||||
with open(os.path.join(example_result_dir, "traj.jsonl"), "a") as f:
|
||||
with open(os.path.join(example_result_dir, "traj.jsonl"), "a", encoding="utf-8") as f:
|
||||
f.write(json.dumps({
|
||||
"instruction": instruction,
|
||||
"initial_state": "initial_state.png"
|
||||
}))
|
||||
}, ensure_ascii=False))
|
||||
f.write("\n")
|
||||
|
||||
# Evaluate the result
|
||||
@@ -159,7 +159,7 @@ def run_single_example_agi(agent, env, example, max_steps, instruction, args, ex
|
||||
if action.get('pending_checks', None):
|
||||
del action['pending_checks']
|
||||
|
||||
with open(os.path.join(example_result_dir, "traj.jsonl"), "a") as f:
|
||||
with open(os.path.join(example_result_dir, "traj.jsonl"), "a", encoding="utf-8") as f:
|
||||
f.write(json.dumps({
|
||||
"step_num": step_idx + 1,
|
||||
"action_timestamp": action_timestamp,
|
||||
@@ -168,7 +168,7 @@ def run_single_example_agi(agent, env, example, max_steps, instruction, args, ex
|
||||
"done": done,
|
||||
"info": info,
|
||||
"screenshot_file": f"step_{step_idx + 1}_{action_timestamp}.png"
|
||||
}))
|
||||
}, ensure_ascii=False))
|
||||
f.write("\n")
|
||||
if done:
|
||||
logger.info("The episode is done.")
|
||||
@@ -220,7 +220,7 @@ def run_single_example_openaicua(agent, env, example, max_steps, instruction, ar
|
||||
if action.get('pending_checks', None):
|
||||
del action['pending_checks']
|
||||
|
||||
with open(os.path.join(example_result_dir, "traj.jsonl"), "a") as f:
|
||||
with open(os.path.join(example_result_dir, "traj.jsonl"), "a", encoding="utf-8") as f:
|
||||
f.write(json.dumps({
|
||||
"step_num": step_idx + 1,
|
||||
"action_timestamp": action_timestamp,
|
||||
@@ -229,7 +229,7 @@ def run_single_example_openaicua(agent, env, example, max_steps, instruction, ar
|
||||
"done": done,
|
||||
"info": info,
|
||||
"screenshot_file": f"step_{step_idx + 1}_{action_timestamp}.png"
|
||||
}))
|
||||
}, ensure_ascii=False))
|
||||
f.write("\n")
|
||||
if done:
|
||||
logger.info("The episode is done.")
|
||||
@@ -329,7 +329,7 @@ def run_single_example_autoglm(agent, env, example, max_steps, instruction, args
|
||||
with open(os.path.join(example_result_dir, f"step_{step_idx + 1}_{action_timestamp}.png"),
|
||||
"wb") as _f:
|
||||
_f.write(obs['screenshot'])
|
||||
with open(os.path.join(example_result_dir, "traj.jsonl"), "a") as f:
|
||||
with open(os.path.join(example_result_dir, "traj.jsonl"), "a", encoding="utf-8") as f:
|
||||
f.write(json.dumps({
|
||||
"step_num": step_idx + 1,
|
||||
"action_timestamp": action_timestamp,
|
||||
@@ -339,7 +339,7 @@ def run_single_example_autoglm(agent, env, example, max_steps, instruction, args
|
||||
"done": done,
|
||||
"info": info,
|
||||
"screenshot_file": f"step_{step_idx + 1}_{action_timestamp}.png"
|
||||
}))
|
||||
}, ensure_ascii=False))
|
||||
f.write("\n")
|
||||
|
||||
if done:
|
||||
@@ -399,7 +399,7 @@ def run_single_example_mano(agent, env, example, max_steps, instruction, args, e
|
||||
with open(os.path.join(example_result_dir, f"step_{step_idx + 1}_{action_timestamp}.png"),
|
||||
"wb") as _f:
|
||||
_f.write(obs['screenshot'])
|
||||
with open(os.path.join(example_result_dir, "traj.jsonl"), "a") as f:
|
||||
with open(os.path.join(example_result_dir, "traj.jsonl"), "a", encoding="utf-8") as f:
|
||||
f.write(json.dumps({
|
||||
"step_num": step_idx + 1,
|
||||
"action_timestamp": action_timestamp,
|
||||
@@ -409,7 +409,7 @@ def run_single_example_mano(agent, env, example, max_steps, instruction, args, e
|
||||
"info": info,
|
||||
"screenshot_file": f"step_{step_idx + 1}_{action_timestamp}.png",
|
||||
"response":response
|
||||
}))
|
||||
}, ensure_ascii=False))
|
||||
f.write("\n")
|
||||
if done:
|
||||
logger.info("The episode is done.")
|
||||
@@ -455,7 +455,7 @@ def run_single_example_uipath(agent, env, example, max_steps, instruction, args,
|
||||
with open(os.path.join(example_result_dir, f"step_{step_idx + 1}_{action_timestamp}.png"),
|
||||
"wb") as _f:
|
||||
_f.write(obs['screenshot'])
|
||||
with open(os.path.join(example_result_dir, "traj.jsonl"), "a") as f:
|
||||
with open(os.path.join(example_result_dir, "traj.jsonl"), "a", encoding="utf-8") as f:
|
||||
f.write(json.dumps({
|
||||
"step_num": step_idx + 1,
|
||||
"action_timestamp": action_timestamp,
|
||||
@@ -465,7 +465,7 @@ def run_single_example_uipath(agent, env, example, max_steps, instruction, args,
|
||||
"done": done,
|
||||
"info": info,
|
||||
"screenshot_file": f"step_{step_idx + 1}_{action_timestamp}.png"
|
||||
}))
|
||||
}, ensure_ascii=False))
|
||||
f.write("\n")
|
||||
if done:
|
||||
logger.info("The episode is done.")
|
||||
@@ -533,7 +533,7 @@ def run_single_example_os_symphony(agent, env, example, max_steps, instruction,
|
||||
"done": done,
|
||||
"info": info,
|
||||
"screenshot_file": img_name
|
||||
}))
|
||||
}, ensure_ascii=False))
|
||||
f.write("\n")
|
||||
with open(os.path.join(example_result_dir, f"traj_{step_idx+1}.json"), "w", encoding="utf-8") as f:
|
||||
json.dump({
|
||||
|
||||
Reference in New Issue
Block a user