Files
AIclinicalresearch/测试和启动.md
AI Clinical Dev Team 9acbb0ae2b feat: complete Dify platform deployment (Day 18)
## Dify 閮ㄧ讲瀹屾垚 鉁?
### 瀹屾垚鐨勫伐浣?1. Docker 闀滃儚鍔犻€熷櫒閰嶇疆
   - 閰嶇疆 5 涓浗鍐呴暅鍍忔簮
   - 澶у箙鎻愬崌涓嬭浇閫熷害鍜屾垚鍔熺巼

2. Dify 闀滃儚鎷夊彇 (鍏?11 涓湇鍔?
   - langgenius/dify-api:1.9.1
   - langgenius/dify-web:1.9.1
   - postgres, redis, weaviate, nginx 绛?   - 鎬诲ぇ灏忕害 2GB锛岃€楁椂绾?15 鍒嗛挓

3. Dify 鏈嶅姟鍚姩
   - 鉁?nginx (80/443)
   - 鉁?api, worker, worker_beat
   - 鉁?web (3000)
   - 鉁?db (PostgreSQL), redis
   - 鉁?weaviate (鍚戦噺鏁版嵁搴?
   - 鉁?sandbox, plugin_daemon, ssrf_proxy

4. Dify 鍒濆鍖栭厤缃?   - 鍒涘缓绠$悊鍛樿处鍙?   - 鍒涘缓搴旂敤: AI Clinical Research
   - 鑾峰彇 API Key: app-VZRn0vMXdmltEJkvatHVGv5j

5. 鍚庣鐜閰嶇疆
   - DIFY_API_URL=http://localhost/v1
   - DIFY_API_KEY 宸查厤缃?
### 鏂囨。鏇存柊
- 鏂板: docs/05-姣忔棩杩涘害/Day18-Dify閮ㄧ讲瀹屾垚.md
- 鏇存柊: docs/04-寮€鍙戣鍒?寮€鍙戦噷绋嬬.md (Day 18 鏍囪涓哄畬鎴?

### 涓嬩竴姝?Day 19-24: 鐭ヨ瘑搴撶郴缁熷紑鍙?- Dify 瀹㈡埛绔皝瑁?- 鐭ヨ瘑搴撶鐞?CRUD
- 鏂囨。涓婁紶涓庡鐞?- @鐭ヨ瘑搴撻泦鎴?- RAG 闂瓟楠岃瘉

---
Progress: 閲岀▼纰?1 (MVP) 85% -> 鐭ヨ瘑搴撶郴缁熷紑鍙戜腑
2025-10-11 08:58:41 +08:00

202 lines
3.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 系统启动和测试指南
## 🚀 快速启动
### 1. 启动后端服务
**打开第一个终端:**
```powershell
cd d:\MyCursor\AIclinicalresearch\backend
npm run dev
```
**预期输出:**
```
🚀 AI临床研究平台 - 后端服务器启动成功!
📍 服务地址: http://localhost:3001
🔍 健康检查: http://localhost:3001/health
```
**如果报错,检查:**
- ✅ PostgreSQL是否运行Docker: `docker ps`
- ✅ Redis是否运行Docker: `docker ps`
-`.env`文件是否配置了API Keys
---
### 2. 启动前端服务
**打开第二个终端:**
```powershell
cd d:\MyCursor\AIclinicalresearch\frontend
npm run dev
```
**预期输出:**
```
VITE v6.x.x ready in xxx ms
➜ Local: http://localhost:3000/
➜ Network: use --host to expose
```
---
### 3. 访问系统
打开浏览器访问:**http://localhost:3000/**
---
## 🔧 常见问题排查
### 问题1获取项目列表失败
**原因:** 后端服务未启动或数据库连接失败
**解决方案:**
1. 检查后端是否启动:访问 http://localhost:3001/health
2. 检查数据库是否运行:
```powershell
docker ps
# 应该看到postgres和redis容器在运行
```
3. 如果数据库未启动:
```powershell
cd d:\MyCursor\AIclinicalresearch
docker-compose up -d
```
---
### 问题2创建项目失败500错误
**原因:** 数据库表未创建或后端代码错误
**解决方案:**
**步骤1检查数据库表是否存在**
```powershell
cd d:\MyCursor\AIclinicalresearch\backend
npx prisma studio
# 打开Prisma Studio检查是否有Project表
```
**步骤2如果表不存在运行迁移**
```powershell
cd d:\MyCursor\AIclinicalresearch\backend
npx prisma migrate dev
```
**步骤3查看后端日志**
- 在运行`npm run dev`的终端中查看错误日志
- 通常会显示具体的错误原因
---
### 问题3API请求404
**原因:** 代理配置或路由问题
**检查清单:**
1. ✅ 后端启动在3001端口
2. ✅ 前端启动在3000端口
3. ✅ `vite.config.ts`中配置了代理
4. ✅ API路由正确注册
---
## 📋 完整启动检查清单
### 前置条件
- [ ] Docker Desktop已安装并运行
- [ ] Node.js已安装v18+
- [ ] PostgreSQL容器已启动
- [ ] Redis容器已启动
- [ ] 后端依赖已安装(`npm install`
- [ ] 前端依赖已安装(`npm install`
- [ ] 后端`.env`文件已配置API Keys
- [ ] 数据库迁移已完成(`prisma migrate dev`
### 启动顺序
1. [ ] 启动Docker容器PostgreSQL + Redis
2. [ ] 启动后端服务3001端口
3. [ ] 启动前端服务3000端口
4. [ ] 访问浏览器测试
---
## 🧪 测试流程
### 1. 测试后端健康检查
```powershell
# 在浏览器或使用curl
curl http://localhost:3001/health
```
**预期响应:**
```json
{
"status": "ok",
"database": "connected",
"timestamp": "2025-10-10T..."
}
```
### 2. 测试获取智能体列表
```powershell
curl http://localhost:3001/api/v1/agents
```
**预期响应:**
```json
{
"success": true,
"data": [
{
"id": "topic-evaluation",
"name": "选题评价智能体",
...
}
]
}
```
### 3. 测试前端页面
1. 访问 http://localhost:3000/
2. 应该看到首页和12个智能体卡片
3. 创建新项目
4. 选择"选题评价智能体"进入对话
---
## 💡 调试技巧
### 查看后端日志
后端使用Pino日志启动时会显示所有请求和错误
### 查看前端控制台
按F12打开开发者工具查看
- ConsoleJavaScript错误
- NetworkAPI请求状态
### 查看数据库
```powershell
cd d:\MyCursor\AIclinicalresearch\backend
npx prisma studio
# 在浏览器中查看和编辑数据库内容
```
---
## 🆘 获取帮助
如果以上方法都无法解决问题,请提供:
1. 后端终端的完整日志
2. 前端浏览器控制台的错误信息
3. 访问 http://localhost:3001/health 的响应
4. `docker ps` 的输出