# ai_code_agent **Repository Path**: xingshuos_admin/ai_code_agent ## Basic Information - **Project Name**: ai_code_agent - **Description**: ai agent - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-12-12 - **Last Updated**: 2025-12-26 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 1. 安装依赖 pip install -r requirements.txt # 2. 启动服务器 python server.py # 或者使用uvicorn直接启动 uvicorn server:app --host 0.0.0.0 --port 8000 --reload # 方式1:直接运行 python main.py # 方式2:使用uvicorn uvicorn src.api.app:create_app --host 0.0.0.0 --port 8001 --reload # 方式3:使用脚本 chmod +x start.sh ./start.sh # 方式4:访问Web界面 打开浏览器访问:http://localhost:8001 # 5. 使用客户端 ``` # 命令行客户端 python -m src.clients.cli_client # 或者直接运行 python src/clients/cli_client.py ``` # 首先,更新FastAPI和uvicorn到最新版本: pip install --upgrade fastapi uvicorn # 框架 原目录结构 ``` ai_code_agent/ ├── core/ # 核心业务逻辑 │ ├── __init__.py │ ├── task_manager.py │ ├── code_generator.py # 原code_generator.py,整合AI后端 │ ├── code_executor.py │ └── sandbox.py ├── ai_backends/ # AI后端实现 │ ├── __init__.py │ ├── base.py # 定义AI后端接口 │ ├── openai_backend.py # 原OpenAIBackend类 │ ├── deepseek_backend.py # 原deepseek_generator.py中的DeepSeekGenerator类 │ └── mock_backend.py # 原MockAIBackend类 ├── config/ # 配置相关 │ ├── __init__.py │ ├── settings.py # 统一配置加载 │ └── env_loader.py # 原env_loader.py ├── server/ # 服务器相关 │ ├── __init__.py │ ├── app.py # 原server.py中的FastAPI app和路由 │ ├── websocket_manager.py # 原ConnectionManager类 │ └── static/ │ └── index.html ├── client.py # 客户端,暂时不变 ├── test_deepseek.py # 测试文件 ├── start.sh ├── config.yaml ├── .env.example ├── requirements.txt ├── README.md └── help.txt ``` # 重构后的项目结构 ``` ai_code_agent/ ├── README.md # 项目说明文档 ├── requirements.txt # Python依赖 ├── config.yaml # 主配置文件 ├── .env.example # 环境变量示例 ├── pyproject.toml # 项目配置(可选) ├── Dockerfile # Docker配置 ├── docker-compose.yml # Docker编排 ├── start.sh # 启动脚本 ├── help.txt # 帮助文档 ├── main.py # 主程序入口 │ ├── src/ # 源代码目录 │ ├── __init__.py │ ├── config/ # 配置管理 │ │ ├── __init__.py │ │ ├── settings.py # 统一配置 │ │ ├── env_loader.py # 环境变量加载 │ │ └── constants.py # 常量定义 │ │ │ ├── core/ # 核心业务逻辑 │ │ ├── __init__.py │ │ ├── models/ # 数据模型 │ │ │ ├── __init__.py │ │ │ ├── task.py # 任务模型 │ │ │ ├── intent.py # 意图模型 │ │ │ └── article.py # 文章模型 │ │ │ │ │ ├── services/ # 业务服务 │ │ │ ├── __init__.py │ │ │ ├── task_manager.py # 任务管理 │ │ │ ├── code_generator.py # 代码生成服务 │ │ │ ├── code_executor.py # 代码执行服务 │ │ │ └── sandbox.py # 安全沙箱 │ │ │ │ │ └── utils/ # 工具函数 │ │ ├── __init__.py │ │ ├── logging.py # 日志配置 │ │ ├── validators.py # 验证器 │ │ └── helpers.py # 辅助函数 │ │ │ ├── ai/ # AI相关模块 │ │ ├── __init__.py │ │ ├── interfaces/ # AI接口抽象 │ │ │ ├── __init__.py │ │ │ └── base_generator.py # AI生成器基类 │ │ │ │ │ ├── providers/ # AI提供商实现 │ │ │ ├── __init__.py │ │ │ ├── deepseek.py # DeepSeek实现 │ │ │ ├── openai.py # OpenAI实现 │ │ │ ├── azure.py # Azure OpenAI实现 │ │ │ ├── local.py # 本地模型实现 │ │ │ └── mock.py # 模拟实现(测试用) │ │ │ │ │ └── prompts/ # 提示词模板 │ │ ├── __init__.py │ │ ├── system_prompts.py # 系统提示词 │ │ ├── code_prompts.py # 代码生成提示词 │ │ └── intent_prompts.py # 意图识别提示词 │ │ │ ├── api/ # API层 │ │ ├── __init__.py │ │ ├── app.py # FastAPI应用 │ │ ├── routers/ # 路由 │ │ │ ├── __init__.py │ │ │ ├── tasks.py # 任务路由 │ │ │ ├── execute.py # 代码执行路由 │ │ │ └── websocket.py # WebSocket路由 │ │ │ │ │ ├── middleware/ # 中间件 │ │ │ ├── __init__.py │ │ │ └── cors.py # CORS中间件 │ │ │ │ │ └── schemas/ # API数据模型 │ │ ├── __init__.py │ │ ├── task.py # 任务相关Schema │ │ ├── code.py # 代码相关Schema │ │ └── response.py # 响应模型 │ │ │ ├── web/ # Web界面 │ │ ├── __init__.py │ │ ├── static/ # 静态文件 │ │ │ ├── index.html # 主页面 │ │ │ ├── css/ │ │ │ │ └── style.css # 样式 │ │ │ └── js/ │ │ │ └── app.js # JavaScript │ │ │ │ │ └── templates/ # 模板(如有) │ │ └── __init__.py │ │ │ └── clients/ # 客户端 │ ├── __init__.py │ ├── web_client.py # Web客户端 │ └── cli_client.py # 命令行客户端 │ ├── tests/ # 测试目录 │ ├── __init__.py │ ├── conftest.py # pytest配置 │ ├── unit/ # 单元测试 │ │ ├── __init__.py │ │ ├── test_ai_providers.py │ │ ├── test_code_generator.py │ │ └── test_task_manager.py │ ├── integration/ # 集成测试 │ │ ├── __init__.py │ │ ├── test_api.py │ │ └── test_executor.py │ └── e2e/ # 端到端测试 │ ├── __init__.py │ └── test_full_flow.py │ └── data/ # 数据目录 ├── output/ # 代码输出 ├── tasks/ # 任务数据 └── logs/ # 日志文件 ```