Files
aue/AI接口测试脚本.md
2026-06-03 13:16:30 +08:00

124 lines
4.7 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.
# AI接口测试脚本
## 登录获取Token
```bash
curl --location --request POST 'http://127.0.0.1:8080/api/auth/login' \
--header 'Content-Type: application/json' \
--data-raw '{
"username": "admin",
"password": "123456"
}'
```
**登录响应**:
```json
{
"code": 200,
"message": "操作成功",
"data": {
"token": "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxIiwidXNlcm5hbWUiOiJhZG1pbiIsImlhdCI6MTc3NzEyNTI0NywiZXhwIjoxNzc3MTMyNDQ3fQ.dXgYqS5WUB6EOgFSSYfKdwc-EnXfUFuWssd92GMy3HOItqyvTe-jpWa1yu2Yac8MHuXeSsZjZfvMxX8G4WF0Iw",
"refreshToken": "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxIiwiaWF0IjoxNzc3MTI1MjQ3LCJleHAiOjE3NzcxMzk2NDd9.tsgZohWhGhtK75hCCdDlE4sr8z9vZgbnfVL86QZhtDZfrTmc0pFQbpmRD8K4jA6P0eBYSoV-0FIcQ41-rV419w",
"expiresIn": 7200000,
"userInfo": {
"id": 1,
"username": "admin",
"realName": "系统管理员",
"email": "admin@system.com",
"phone": "13800000000",
"avatar": null,
"userType": 1,
"lastLoginTime": null
}
},
"timestamp": "2026-04-25 13:54:07",
"success": true
}
```
## 测试命令
### 1. AI流式问答接口
```bash
curl --location --request POST 'http://127.0.0.1:8080/api/ai/chat/stream' \
--header 'Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxIiwidXNlcm5hbWUiOiJhZG1pbiIsImlhdCI6MTc3NzIxODYzMywiZXhwIjoxNzc3MjI1ODMzfQ.U1bkByjiPkA3GcUagPRTG1n08aPjW8Tj0vVSclUIqoOgOpZVHAo5a4b8b44Ewt0Td-xdCk9u_pTzdWzWVuzR1Q' \
--header 'Content-Type: application/json' \
--data-raw '{
"message": "2026三峡在哪",
"id": "test_req_123",
"session_id": "test_sess_123"
}'
```
### 2. 获取用户会话列表接口
```bash
curl --location --request GET 'http://127.0.0.1:8080/api/ai/sessions?page=1&pageSize=10' \
--header 'Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxIiwidXNlcm5hbWUiOiJhZG1pbiIsImlhdCI6MTc3NzEyNTI0NywiZXhwIjoxNzc3MTMyNDQ3fQ.dXgYqS5WUB6EOgFSSYfKdwc-EnXfUFuWssd92GMy3HOItqyvTe-jpWa1yu2Yac8MHuXeSsZjZfvMxX8G4WF0Iw'
```
### 3. 获取会话详情接口
```bash
curl --location --request GET 'http://127.0.0.1:8080/api/ai/session/test_sess_123?page=1&pageSize=20' \
--header 'Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxIiwidXNlcm5hbWUiOiJhZG1pbiIsImlhdCI6MTc3NzEyNTI0NywiZXhwIjoxNzc3MTMyNDQ3fQ.dXgYqS5WUB6EOgFSSYfKdwc-EnXfUFuWssd92GMy3HOItqyvTe-jpWa1yu2Yac8MHuXeSsZjZfvMxX8G4WF0Iw'
```
### 4. 获取消息引用信息接口
```bash
curl --location --request GET 'http://127.0.0.1:8080/api/ai/message/2/references' \
--header 'Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxIiwidXNlcm5hbWUiOiJhZG1pbiIsImlhdCI6MTc3NzEyNTI0NywiZXhwIjoxNzc3MTMyNDQ3fQ.dXgYqS5WUB6EOgFSSYfKdwc-EnXfUFuWssd92GMy3HOItqyvTe-jpWa1yu2Yac8MHuXeSsZjZfvMxX8G4WF0Iw'
```
### 5. 获取会话引用信息接口
```bash
curl --location --request GET 'http://127.0.0.1:8080/api/ai/session/test_sess_123/references' \
--header 'Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxIiwidXNlcm5hbWUiOiJhZG1pbiIsImlhdCI6MTc3NzEyNTI0NywiZXhwIjoxNzc3MTMyNDQ3fQ.dXgYqS5WUB6EOgFSSYfKdwc-EnXfUFuWssd92GMy3HOItqyvTe-jpWa1yu2Yac8MHuXeSsZjZfvMxX8G4WF0Iw'
```
### 6. 删除单个会话接口
```bash
curl --location --request DELETE 'http://127.0.0.1:8080/api/ai/session/test_sess_123' \
--header 'Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxIiwidXNlcm5hbWUiOiJhZG1pbiIsImlhdCI6MTc3NzEyNTI0NywiZXhwIjoxNzc3MTMyNDQ3fQ.dXgYqS5WUB6EOgFSSYfKdwc-EnXfUFuWssd92GMy3HOItqyvTe-jpWa1yu2Yac8MHuXeSsZjZfvMxX8G4WF0Iw'
```
### 7. 批量删除会话接口
```bash
curl --location --request DELETE 'http://127.0.0.1:8080/api/ai/sessions' \
--header 'Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxIiwidXNlcm5hbWUiOiJhZG1pbiIsImlhdCI6MTc3NzEyNTI0NywiZXhwIjoxNzc3MTMyNDQ3fQ.dXgYqS5WUB6EOgFSSYfKdwc-EnXfUFuWssd92GMy3HOItqyvTe-jpWa1yu2Yac8MHuXeSsZjZfvMxX8G4WF0Iw' \
--header 'Content-Type: application/json' \
--data-raw '[
"test_sess_123",
"test_sess_456"
]'
```
## 注意事项
1. **Token有效期**token有效期为2小时7200秒过期后需要重新登录获取
2. **会话ID**测试时需要使用实际存在的会话ID
3. **消息ID**获取引用信息时需要使用实际存在的消息ID
4. **权限验证**:确保测试使用的账号有权限访问对应的会话
5. **环境配置**:确保服务运行在 `http://127.0.0.1:8080`
## 测试流程
1. 首先执行登录命令获取token
2. 将获取到的token替换到各个测试命令中
3. 按照顺序执行测试命令,验证接口功能
4. 检查响应结果是否符合预期
## 故障排查
- **401错误**token无效或过期需要重新登录
- **403错误**:权限不足,检查用户是否有权限访问该资源
- **400错误**:参数错误,检查请求参数是否正确
- **500错误**:服务器内部错误,查看服务器日志获取详细信息