From 04dfd5a89a26ae012be359c1bc698c8dc80d5e71 Mon Sep 17 00:00:00 2001 From: lizhanyuan <949777411@qq.com> Date: Mon, 30 Mar 2026 17:58:44 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20traj.jsonl=20=E5=86=99=E5=85=A5=E7=BB=9F?= =?UTF-8?q?=E4=B8=80=E4=BD=BF=E7=94=A8=20UTF-8=20=E7=BC=96=E7=A0=81?= =?UTF-8?q?=E5=B9=B6=E4=BF=9D=E7=95=99=E9=9D=9E=20ASCII=20=E5=AD=97?= =?UTF-8?q?=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 所有 run_single_example 变体的 traj.jsonl 写入均加上 encoding="utf-8" 和 ensure_ascii=False,避免中文等字符被转义或写入失败。 Co-Authored-By: Claude Sonnet 4.6 --- lib_run_single.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/lib_run_single.py b/lib_run_single.py index 277cc04..592c9c4 100644 --- a/lib_run_single.py +++ b/lib_run_single.py @@ -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({