Files
LocalAgent/main.py
Mimikko-zeus 0a92355bfb feat: enhance LocalAgent configuration and UI components
- Updated .env.example to provide clearer configuration instructions and API key setup.
- Removed debug_env.py as it was no longer needed.
- Refactored main.py to streamline application initialization and workspace setup.
- Introduced a new HistoryManager for managing task execution history.
- Enhanced UI components in chat_view.py and task_guide_view.py to improve user interaction and code preview functionality.
- Added loading indicators and improved task history display in the UI.
- Implemented unit tests for history management and intent classification.
2026-01-07 10:29:13 +08:00

124 lines
3.3 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_environment() -> bool:
"""检查运行环境"""
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
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)
# 检查环境
if not check_environment():
sys.exit(1)
# 创建工作目录
workspace = setup_workspace()
print(f"工作目录: {workspace}")
print(f"输入目录: {workspace / 'input'}")
print(f"输出目录: {workspace / 'output'}")
print(f"日志目录: {workspace / 'logs'}")
print(f"代码目录: {workspace / 'codes'}")
print("=" * 50)
# 启动应用
app = LocalAgentApp(PROJECT_ROOT)
app.run()
if __name__ == "__main__":
main()