feat: refactor API key configuration and enhance application initialization
- Renamed `check_environment` to `check_api_key_configured` for clarity, simplifying the API key validation logic. - Removed the blocking behavior of the API key check during application startup, allowing the app to run while providing a prompt for configuration. - Updated `LocalAgentApp` to accept an `api_configured` parameter, enabling conditional messaging for API key setup. - Enhanced the `SandboxRunner` to support backup management and improved execution result handling with detailed metrics. - Integrated data governance strategies into the `HistoryManager`, ensuring compliance and improved data management. - Added privacy settings and metrics tracking across various components to enhance user experience and application safety.
This commit is contained in:
46
main.py
46
main.py
@@ -50,37 +50,10 @@ load_dotenv(ENV_PATH)
|
||||
from app.agent import LocalAgentApp
|
||||
|
||||
|
||||
def check_environment() -> bool:
|
||||
"""检查运行环境"""
|
||||
def check_api_key_configured() -> bool:
|
||||
"""检查 API Key 是否已配置"""
|
||||
api_key = os.getenv("LLM_API_KEY")
|
||||
|
||||
if not api_key or api_key == "your_api_key_here":
|
||||
print("=" * 50)
|
||||
print("错误: 未配置 LLM API Key")
|
||||
print("=" * 50)
|
||||
print()
|
||||
print("请按以下步骤配置:")
|
||||
print("1. 复制 .env.example 为 .env")
|
||||
print("2. 在 .env 中设置 LLM_API_KEY=你的API密钥")
|
||||
print()
|
||||
print("获取 API Key: https://siliconflow.cn")
|
||||
print("=" * 50)
|
||||
|
||||
# 显示 GUI 错误提示
|
||||
root = tk.Tk()
|
||||
root.withdraw()
|
||||
messagebox.showerror(
|
||||
"配置错误",
|
||||
"未配置 LLM API Key\n\n"
|
||||
"请按以下步骤配置:\n"
|
||||
"1. 复制 .env.example 为 .env\n"
|
||||
"2. 在 .env 中设置 LLM_API_KEY=你的API密钥\n\n"
|
||||
"获取 API Key: https://siliconflow.cn"
|
||||
)
|
||||
root.destroy()
|
||||
return False
|
||||
|
||||
return True
|
||||
return api_key and api_key != "your_api_key_here"
|
||||
|
||||
|
||||
def setup_workspace():
|
||||
@@ -100,10 +73,6 @@ def main():
|
||||
print("LocalAgent - Windows 本地 AI 执行助手")
|
||||
print("=" * 50)
|
||||
|
||||
# 检查环境
|
||||
if not check_environment():
|
||||
sys.exit(1)
|
||||
|
||||
# 创建工作目录
|
||||
workspace = setup_workspace()
|
||||
|
||||
@@ -114,8 +83,13 @@ def main():
|
||||
print(f"代码目录: {workspace / 'codes'}")
|
||||
print("=" * 50)
|
||||
|
||||
# 启动应用
|
||||
app = LocalAgentApp(PROJECT_ROOT)
|
||||
# 检查 API Key 是否配置(不阻止启动,只传递状态)
|
||||
api_configured = check_api_key_configured()
|
||||
if not api_configured:
|
||||
print("提示: 未配置 API Key,请在应用内点击「设置」进行配置")
|
||||
|
||||
# 启动应用(传递 API 配置状态)
|
||||
app = LocalAgentApp(PROJECT_ROOT, api_configured=api_configured)
|
||||
app.run()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user