LQY1234/agent-react
0
1# 云端部署指南2 3## 部署选项(推荐 Railway)4 5### 方案 1: Railway(推荐 ⭐)6最简单快速的云部署方案,支持免费额度。7 8**步骤:**91. 注册账号:https://railway.app102. 连接 GitHub 账号113. 创建新项目 → 选择 GitHub 仓库124. 设置环境变量(参考下面的 `.env.example`)135. 自动部署完成14 15**环境变量配置:**16在 Railway 仪表板中添加以下环境变量:17```18SERPAPI_API_KEY=your_serpapi_key_here19LLM_API_KEY=your_llm_api_key20LLM_MODEL_ID=Qwen/Qwen2.5-Coder-32B-Instruct21LLM_BASE_URL=https://api-inference.modelscope.cn/v1/22FLASK_ENV=production23```24 25---26 27### 方案 2: Vercel(适合简单应用)28**步骤:**291. 注册:https://vercel.com302. GitHub 授权313. Import 项目324. 设置环境变量335. 部署34 35**注意:** Vercel 默认不支持长时间运行的请求,可能导致 agent 搜索超时。36 37---38 39### 方案 3: PythonAnywhere(完全为 Python 优化)40**步骤:**411. 注册免费账号:https://www.pythonanywhere.com422. 上传代码或从 GitHub clone433. 创建 Web app → Flask444. 配置虚拟环境和依赖455. 设置 WSGI 文件46 47---48 49## 本地快速测试50 51在部署前,确保本地运行正常:52```bash53# 安装依赖54source .venv/bin/activate55pip install -r requirements.txt56 57# 运行58python web.py59```60 61访问 http://127.0.0.1:500162 63---64 65## 部署前检查清单66 67- [ ] 已上传代码到 GitHub 公开/私有仓库68- [ ] 已生成 `requirements.txt`69- [ ] 已生成 `Procfile`(如果使用 Heroku/Railway)70- [ ] 已配置所有环境变量(API 密钥)71- [ ] `.env` 文件已添加到 `.gitignore`(防止泄露密钥)72- [ ] 本地测试通过73 74---75 76## 推荐的快速部署流程(Railway)77 78```bash79# 1. 初始化 git 仓库(如果还没有)80git init81git add .82git commit -m "Init: Agent ReAct web interface"83git remote add origin https://github.com/YOUR_USERNAME/your-repo.git84git branch -M main85git push -u origin main86 87# 2. 在 Railway 仪表板中:88# - 连接 GitHub89# - 选择刚推送的仓库90# - 添加环境变量91# - 自动部署开始92```93 94完成后,你会得到一个公开 URL 如:95```96https://your-app-123abc.railway.app97```98 99---100 101## 故障排查102 103### 502 Bad Gateway / 超时104- 原因:web 搜索或 LLM 调用耗时过长105- 解决:在云平台增加超时配置或使用异步处理106 107### 环境变量未加载108- 检查环境变量名称是否正确109- 重启应用服务110 111### API 密钥无效112- 确保 API 密钥正确113- 检查 API 配额是否已用完114 115---116 117## 后续优化118 119部署成功后可考虑:120- [ ] 添加请求日志和监控121- [ ] 实现异步任务队列(Celery + Redis)122- [ ] 添加用户认证123- [ ] 数据库存储对话历史124- [ ] CDN 加速前端资源125 