code_run自动注入常用import+memory路径; ljqCtrl_sop补充文本输入方法

This commit is contained in:
Liang Jiaqing
2026-03-24 00:00:20 +08:00
parent 515b0cd985
commit 5643bfb5f0
2 changed files with 4 additions and 2 deletions

3
ga.py
View File

@@ -20,7 +20,8 @@ def code_run(code, code_type="python", timeout=60, cwd=None, code_cwd=None, stop
cwd = cwd or os.path.join(script_dir, 'temp'); tmp_path = None
if code_type == "python":
tmp_file = tempfile.NamedTemporaryFile(suffix=".ai.py", delete=False, mode='w', encoding='utf-8', dir=code_cwd)
tmp_file.write(code)
_mem = os.path.join(script_dir, 'memory')
tmp_file.write(f"import sys, os, json, re, time; sys.path.append(r'{_mem}')\n" + code)
tmp_path = tmp_file.name
tmp_file.close()
cmd = [sys.executable, "-X", "utf8", "-u", tmp_path]