- 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.
98 lines
2.7 KiB
Python
98 lines
2.7 KiB
Python
"""
|
||
LocalAgent - Windows 本地 AI 执行助手 (MVP)
|
||
|
||
========================================
|
||
配置说明
|
||
========================================
|
||
1. 复制 .env.example 为 .env
|
||
2. 在 .env 中填入你的 SiliconFlow API Key:
|
||
LLM_API_KEY=sk-xxxxx
|
||
|
||
========================================
|
||
运行方式
|
||
========================================
|
||
方式一:使用 Anaconda
|
||
conda create -n localagent python=3.10
|
||
conda activate localagent
|
||
pip install -r requirements.txt
|
||
python main.py
|
||
|
||
方式二:直接运行(需已安装依赖)
|
||
python main.py
|
||
|
||
========================================
|
||
测试方法
|
||
========================================
|
||
1. 对话测试:输入 "今天天气怎么样" → 应识别为 chat
|
||
2. 执行测试:
|
||
- 将测试文件放入 workspace/input 目录
|
||
- 输入 "把这些文件复制一份" → 应识别为 execution
|
||
- 确认执行后,检查 workspace/output 目录
|
||
|
||
========================================
|
||
"""
|
||
|
||
import os
|
||
import sys
|
||
import tkinter as tk
|
||
from tkinter import messagebox
|
||
from pathlib import Path
|
||
from dotenv import load_dotenv
|
||
|
||
# 确保项目根目录在 Python 路径中
|
||
PROJECT_ROOT = Path(__file__).parent
|
||
ENV_PATH = PROJECT_ROOT / ".env"
|
||
sys.path.insert(0, str(PROJECT_ROOT))
|
||
|
||
# 在导入其他模块之前先加载环境变量
|
||
load_dotenv(ENV_PATH)
|
||
|
||
from app.agent import LocalAgentApp
|
||
|
||
|
||
def check_api_key_configured() -> bool:
|
||
"""检查 API Key 是否已配置"""
|
||
api_key = os.getenv("LLM_API_KEY")
|
||
return api_key and api_key != "your_api_key_here"
|
||
|
||
|
||
def setup_workspace():
|
||
"""创建工作目录"""
|
||
workspace = PROJECT_ROOT / "workspace"
|
||
(workspace / "input").mkdir(parents=True, exist_ok=True)
|
||
(workspace / "output").mkdir(parents=True, exist_ok=True)
|
||
(workspace / "logs").mkdir(parents=True, exist_ok=True)
|
||
(workspace / "codes").mkdir(parents=True, exist_ok=True)
|
||
|
||
return workspace
|
||
|
||
|
||
def main():
|
||
"""主入口"""
|
||
print("=" * 50)
|
||
print("LocalAgent - Windows 本地 AI 执行助手")
|
||
print("=" * 50)
|
||
|
||
# 创建工作目录
|
||
workspace = setup_workspace()
|
||
|
||
print(f"工作目录: {workspace}")
|
||
print(f"输入目录: {workspace / 'input'}")
|
||
print(f"输出目录: {workspace / 'output'}")
|
||
print(f"日志目录: {workspace / 'logs'}")
|
||
print(f"代码目录: {workspace / 'codes'}")
|
||
print("=" * 50)
|
||
|
||
# 检查 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()
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main()
|