From fa98abcea580ac3bc7a8793fb4f082ce1a352271 Mon Sep 17 00:00:00 2001 From: Liang Jiaqing Date: Tue, 3 Feb 2026 18:13:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=9AStreamlit=20fragment?= =?UTF-8?q?=E6=80=A7=E8=83=BD=20+=20code=5Frun=E7=81=B5=E6=B4=BB=E6=80=A7?= =?UTF-8?q?=20+=20LLM=20context=5Fwin=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- agentapp.py | 6 ++++-- ga.py | 12 ++++++------ sidercall.py | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/agentapp.py b/agentapp.py index 735eec1..70373bc 100644 --- a/agentapp.py +++ b/agentapp.py @@ -74,12 +74,14 @@ for msg in st.session_state.messages: with st.chat_message(msg["role"]): st.markdown(msg["content"]) -with st.sidebar: +@st.fragment +def render_llm_switcher(): current_idx = st.session_state.get("llm_no", 0) st.caption(f"LLM Core: {current_idx}") if st.button("切换备用链路"): st.session_state.llm_no = (st.session_state.get("llm_no", 0) + 1) % len(llmclient.raw_apis) - st.rerun() + st.rerun(scope="fragment") +with st.sidebar: render_llm_switcher() if prompt := st.chat_input("请输入指令"): st.session_state.messages.append({"role": "user", "content": prompt}) diff --git a/ga.py b/ga.py index 68e41cb..97d15d0 100644 --- a/ga.py +++ b/ga.py @@ -7,18 +7,17 @@ sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) from agent_loop import BaseHandler, StepOutcome, try_call_generator -def code_run(code: str, code_type: str = "python", timeout: int = 60, cwd: str = None): - """ - 针对 Windows 优化的双模态执行器 +def code_run(code, code_type="python", timeout=60, cwd=None, code_cwd=None): + """代码执行器 python: 运行复杂的 .py 脚本(文件模式) - powershell: 运行单行指令(命令模式) + powershell/bash: 运行单行指令(命令模式) 优先使用python,仅在必要系统操作时使用powershell。 """ 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.path.join(os.getcwd(), 'temp'); tmp_path = None if code_type == "python": - tmp_file = tempfile.NamedTemporaryFile(suffix=".py", delete=False, mode='w', encoding='utf-8') + tmp_file = tempfile.NamedTemporaryFile(suffix=".ai.py", delete=False, mode='w', encoding='utf-8', dir=code_cwd) tmp_file.write(code) tmp_path = tmp_file.name tmp_file.close() @@ -274,7 +273,8 @@ class GenericAgentHandler(BaseHandler): timeout = args.get("timeout", 60) raw_path = os.path.join(self.cwd, args.get("cwd", './')) cwd = os.path.normpath(os.path.abspath(raw_path)) - result = yield from code_run(code, code_type, timeout, cwd) + code_cwd = os.path.normpath(self.cwd) + result = yield from code_run(code, code_type, timeout, cwd, code_cwd=code_cwd) next_prompt = self._get_anchor_prompt() + warning return StepOutcome(result, next_prompt=next_prompt) diff --git a/sidercall.py b/sidercall.py index bf52f28..017780a 100644 --- a/sidercall.py +++ b/sidercall.py @@ -18,7 +18,7 @@ class SiderLLMSession: return ''.join(self._core.chat(prompt, model)) class LLMSession: - def __init__(self, api_key=oai_apikey, api_base=oai_apibase, model=oai_model, context_win=32000): + def __init__(self, api_key=oai_apikey, api_base=oai_apibase, model=oai_model, context_win=16000): self.api_key = api_key self.api_base = api_base self.raw_msgs = []