optimize: add -X utf8 to python subprocess in ga.py to fix unicode output issues

This commit is contained in:
Liang Jiaqing
2026-01-29 18:41:46 +08:00
parent ef00aaf641
commit 7810f38f44
4 changed files with 12 additions and 10 deletions

View File

@@ -94,7 +94,7 @@ class TMWebDriver:
auto_switch_newtab = data.get('auto_switch_newtab', False)
try:
result = self.execute_js(code, timeout=timeout, session_id=session_id, auto_switch_newtab=auto_switch_newtab)
print('remote', result)
print('[remote result]', str(result)[:500])
newTabs = result.get('newTabs', []) if isinstance(result, dict) else []
return json.dumps({'result': result, 'newTabs': newTabs}, ensure_ascii=False)
except Exception as e:

13
ga.py
View File

@@ -16,16 +16,16 @@ def code_run(code: str, code_type: str = "python", timeout: int = 60, cwd: str =
"""
preview = (code[:60].replace('\n', ' ') + '...') if len(code) > 60 else code.strip()
yield f"[Action] Running {code_type} in {os.path.basename(cwd)}: {preview}\n"
cwd = cwd or os.getcwd()
cwd = cwd or os.getcwd(); tmp_path = None
if code_type == "python":
tmp_file = tempfile.NamedTemporaryFile(suffix=".py", delete=False, mode='w', encoding='utf-8')
tmp_file.write(code)
tmp_path = tmp_file.name
tmp_file.close()
cmd = ["python", "-u", tmp_path]
elif code_type == "powershell":
cmd = ["powershell", "-NoProfile", "-NonInteractive", "-Command", code]
tmp_path = None
cmd = ["python", "-X", "utf8", "-u", tmp_path]
elif code_type in ["powershell", "bash"]:
if os.name == 'nt': cmd = ["powershell", "-NoProfile", "-NonInteractive", "-Command", code]
else: cmd = ["bash", "-c", code]
else:
return {"status": "error", "msg": f"不支持的类型: {code_type}"}
print("code run output:")
@@ -398,7 +398,8 @@ class GenericAgentHandler(BaseHandler):
next_prompt = '''### [总结提炼经验] 既然你觉得当前任务有重要信息需要记忆,请提取最近一次任务中【事实验证成功且长期有效】的环境事实与用户偏好,更新至全局记忆。
1. 严禁记录任何任务特定中间执行过程或临时变量经验,那是过程记忆不是全局记忆。
2. 若无高价值新事实,那就不更新任何内容。
3. 尽量先查看现有全局记忆形式,仿照形式且避免冗余,insight也要添加对全局记忆的短印象来提醒存在性。'''
3. 尽量先查看现有全局记忆形式,仅作少量修改不要影响其余部分。insight也要同步更新全局记忆的短印象来提醒存在性。
4. 优先使用file_read和file_patch来保证少量修改。'''
yield "[Info] Start distilling good memory for long-term storage.\n"
return StepOutcome({"status": "success"}, next_prompt=next_prompt)

View File

@@ -816,8 +816,9 @@ def get_main_block(driver):
if type(html) is not str:
time.sleep(2)
html = driver.execute_js(js_optHTML)
else:
print('[STRANGE TYPE]', str(html)[:500])
if type(html) is not str:
print('[STRANGE TYPE]', type(html), str(html)[:500])
return html
return html

View File

@@ -1,7 +1,7 @@
[
{"type": "function", "function": {
"name": "code_run",
"description": "针对 Windows 优化的双模态代码执行器。优先使用 python 运行复杂逻辑,仅在必要系统操作时使用 powershell。注意执行的代码必须以 ```python 或 ```powershell 代码块的形式包含在回复正文中。严禁在代码中硬编码大量数据,如有需要应通过文件读取。执行时间限制为 60s。",
"description": "针对 Windows 优化的双模态代码执行器。优先使用python仅在必要系统操作时使用 powershell。注意执行的代码必须以 ```python 或 ```powershell 代码块的形式包含在回复正文中。严禁在代码中硬编码大量数据,如有需要应通过文件读取。执行时间限制为 60s。",
"parameters": {"type": "object", "properties": {
"type": {"type": "string", "enum": ["python", "powershell"], "description": "执行环境类型,默认为 python。", "default": "python"},
"timeout": {"type": "integer", "description": "执行超时时间(秒),默认 60。", "default": 60},