Open
Conversation
- llmcore.py: 新增 reload_mykeys() 强制重载和 reload_mykeys_if_changed() 按文件 mtime 自动检测 - agentmain.py: 提取 _build_llm_clients(),新增 reload_llm_configs(force),next_llm/list_llms 自动触发检测 - frontends/stapp.py: 侧边栏新增"重载 LLM 配置"按钮
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
动机
目前修改
mykey.py后必须重启整个进程才能生效。对于需要频繁调试 API Key、切换模型或调整提供商配置的场景,这很不方便。改动内容
llmcore.py
reload_mykeys():通过importlib.reload(mykey)强制重新导入 mykey.py,刷新全局mykeys和proxies缓存reload_mykeys_if_changed():基于文件 mtime 检测,仅在 mykey.py/mykey.json 被修改后才执行 reload,未修改时零开销直接返回缓存agentmain.py
_build_llm_clients()方法,将__init__中的 LLM 构建逻辑独立出来,避免重复代码reload_llm_configs(force=False):force=False(默认):通过 mtime 自动检测,文件没变就跳过force=True:强制重载,用于手动触发场景backend.history)并迁移到新 clientllm_no防止越界next_llm()和list_llms()开头自动调用reload_llm_configs(),所有前端(Streamlit、Telegram、QQ、飞书、钉钉、企微、WebView)无需任何改动即可受益frontends/stapp.py
force=True),用于手动强制重载使用方式
自动模式(推荐):修改 mykey.py → 点「切换备用链路」或任何触发
next_llm()/list_llms()的操作 → 自动检测文件变化并重载手动模式:点「🔄 重载 LLM 配置」按钮 → 强制重载(即使文件未变也重建所有 client)
兼容性
next_llm(n)/list_llms()行为完全向后兼容