optimize: add -X utf8 to python subprocess in ga.py to fix unicode output issues
This commit is contained in:
@@ -94,7 +94,7 @@ class TMWebDriver:
|
|||||||
auto_switch_newtab = data.get('auto_switch_newtab', False)
|
auto_switch_newtab = data.get('auto_switch_newtab', False)
|
||||||
try:
|
try:
|
||||||
result = self.execute_js(code, timeout=timeout, session_id=session_id, auto_switch_newtab=auto_switch_newtab)
|
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 []
|
newTabs = result.get('newTabs', []) if isinstance(result, dict) else []
|
||||||
return json.dumps({'result': result, 'newTabs': newTabs}, ensure_ascii=False)
|
return json.dumps({'result': result, 'newTabs': newTabs}, ensure_ascii=False)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
13
ga.py
13
ga.py
@@ -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()
|
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"
|
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":
|
if code_type == "python":
|
||||||
tmp_file = tempfile.NamedTemporaryFile(suffix=".py", delete=False, mode='w', encoding='utf-8')
|
tmp_file = tempfile.NamedTemporaryFile(suffix=".py", delete=False, mode='w', encoding='utf-8')
|
||||||
tmp_file.write(code)
|
tmp_file.write(code)
|
||||||
tmp_path = tmp_file.name
|
tmp_path = tmp_file.name
|
||||||
tmp_file.close()
|
tmp_file.close()
|
||||||
cmd = ["python", "-u", tmp_path]
|
cmd = ["python", "-X", "utf8", "-u", tmp_path]
|
||||||
elif code_type == "powershell":
|
elif code_type in ["powershell", "bash"]:
|
||||||
cmd = ["powershell", "-NoProfile", "-NonInteractive", "-Command", code]
|
if os.name == 'nt': cmd = ["powershell", "-NoProfile", "-NonInteractive", "-Command", code]
|
||||||
tmp_path = None
|
else: cmd = ["bash", "-c", code]
|
||||||
else:
|
else:
|
||||||
return {"status": "error", "msg": f"不支持的类型: {code_type}"}
|
return {"status": "error", "msg": f"不支持的类型: {code_type}"}
|
||||||
print("code run output:")
|
print("code run output:")
|
||||||
@@ -398,7 +398,8 @@ class GenericAgentHandler(BaseHandler):
|
|||||||
next_prompt = '''### [总结提炼经验] 既然你觉得当前任务有重要信息需要记忆,请提取最近一次任务中【事实验证成功且长期有效】的环境事实与用户偏好,更新至全局记忆。
|
next_prompt = '''### [总结提炼经验] 既然你觉得当前任务有重要信息需要记忆,请提取最近一次任务中【事实验证成功且长期有效】的环境事实与用户偏好,更新至全局记忆。
|
||||||
1. 严禁记录任何任务特定中间执行过程或临时变量经验,那是过程记忆不是全局记忆。
|
1. 严禁记录任何任务特定中间执行过程或临时变量经验,那是过程记忆不是全局记忆。
|
||||||
2. 若无高价值新事实,那就不更新任何内容。
|
2. 若无高价值新事实,那就不更新任何内容。
|
||||||
3. 尽量先查看现有全局记忆形式,仿照形式且避免冗余,insight也要添加对全局记忆的短印象来提醒存在性。'''
|
3. 尽量先查看现有全局记忆形式,仅作少量修改不要影响其余部分。insight也要同步更新全局记忆的短印象来提醒存在性。
|
||||||
|
4. 优先使用file_read和file_patch来保证少量修改。'''
|
||||||
yield "[Info] Start distilling good memory for long-term storage.\n"
|
yield "[Info] Start distilling good memory for long-term storage.\n"
|
||||||
return StepOutcome({"status": "success"}, next_prompt=next_prompt)
|
return StepOutcome({"status": "success"}, next_prompt=next_prompt)
|
||||||
|
|
||||||
|
|||||||
@@ -816,8 +816,9 @@ def get_main_block(driver):
|
|||||||
if type(html) is not str:
|
if type(html) is not str:
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
html = driver.execute_js(js_optHTML)
|
html = driver.execute_js(js_optHTML)
|
||||||
else:
|
if type(html) is not str:
|
||||||
print('[STRANGE TYPE]', str(html)[:500])
|
print('[STRANGE TYPE]', type(html), str(html)[:500])
|
||||||
|
return html
|
||||||
return html
|
return html
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
[
|
[
|
||||||
{"type": "function", "function": {
|
{"type": "function", "function": {
|
||||||
"name": "code_run",
|
"name": "code_run",
|
||||||
"description": "针对 Windows 优化的双模态代码执行器。优先使用 python 运行复杂逻辑,仅在必要系统操作时使用 powershell。注意:执行的代码必须以 ```python 或 ```powershell 代码块的形式包含在回复正文中。严禁在代码中硬编码大量数据,如有需要应通过文件读取。执行时间限制为 60s。",
|
"description": "针对 Windows 优化的双模态代码执行器。优先使用python,仅在必要系统操作时使用 powershell。注意:执行的代码必须以 ```python 或 ```powershell 代码块的形式包含在回复正文中。严禁在代码中硬编码大量数据,如有需要应通过文件读取。执行时间限制为 60s。",
|
||||||
"parameters": {"type": "object", "properties": {
|
"parameters": {"type": "object", "properties": {
|
||||||
"type": {"type": "string", "enum": ["python", "powershell"], "description": "执行环境类型,默认为 python。", "default": "python"},
|
"type": {"type": "string", "enum": ["python", "powershell"], "description": "执行环境类型,默认为 python。", "default": "python"},
|
||||||
"timeout": {"type": "integer", "description": "执行超时时间(秒),默认 60。", "default": 60},
|
"timeout": {"type": "integer", "description": "执行超时时间(秒),默认 60。", "default": 60},
|
||||||
|
|||||||
Reference in New Issue
Block a user