134 lines
4.5 KiB
Markdown
134 lines
4.5 KiB
Markdown
|
|
# AI分析指令修复说明
|
|||
|
|
|
|||
|
|
## 问题描述
|
|||
|
|
用户输入"分析张三"时,AI能够正确识别意图为`analyzeReport`,但系统没有使用AI识别的参数(keyword: "张三"),而是继续使用正则匹配,导致无法获取报告数据,最终返回"暂不提供此服务"。
|
|||
|
|
|
|||
|
|
## 根本原因
|
|||
|
|
1. AI意图识别成功后,对于分析类指令(analyzeReport/analyzeProfile)返回`false`继续处理
|
|||
|
|
2. 但后续代码仍然使用正则匹配`parseAnalyzeReportKeyword(text)`获取关键词
|
|||
|
|
3. AI识别的参数(`intent.params.keyword`)被丢弃,没有传递给后续逻辑
|
|||
|
|
|
|||
|
|
## 解决方案
|
|||
|
|
|
|||
|
|
### 1. 保存AI识别的意图
|
|||
|
|
在AI意图识别部分,当识别到分析类指令时,保存完整的intent对象:
|
|||
|
|
|
|||
|
|
```javascript
|
|||
|
|
let aiRecognizedIntent = null
|
|||
|
|
if (intent.action === 'analyzeReport' || intent.action === 'analyzeProfile' || intent.action === 'analyzeData') {
|
|||
|
|
aiRecognizedIntent = intent
|
|||
|
|
console.log('分析类指令,保存AI识别的参数:', aiRecognizedIntent)
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 2. 优先使用AI识别的参数
|
|||
|
|
在报告数据获取逻辑中,优先使用AI识别的参数,如果没有则回退到正则匹配:
|
|||
|
|
|
|||
|
|
```javascript
|
|||
|
|
let reportId = ''
|
|||
|
|
let reportKeyword = ''
|
|||
|
|
let profileKeyword = ''
|
|||
|
|
|
|||
|
|
if (aiRecognizedIntent) {
|
|||
|
|
console.log('使用AI识别的参数:', aiRecognizedIntent.params)
|
|||
|
|
if (aiRecognizedIntent.action === 'analyzeReport') {
|
|||
|
|
reportId = aiRecognizedIntent.params.reportId || ''
|
|||
|
|
reportKeyword = aiRecognizedIntent.params.keyword || ''
|
|||
|
|
} else if (aiRecognizedIntent.action === 'analyzeProfile') {
|
|||
|
|
profileKeyword = aiRecognizedIntent.params.keyword || aiRecognizedIntent.params.userId || ''
|
|||
|
|
}
|
|||
|
|
} else {
|
|||
|
|
// 回退到正则匹配
|
|||
|
|
console.log('回退到正则匹配')
|
|||
|
|
reportId = this.parseAnalyzeReportId(text)
|
|||
|
|
reportKeyword = this.parseAnalyzeReportKeyword(text)
|
|||
|
|
profileKeyword = ''
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
## 执行流程
|
|||
|
|
|
|||
|
|
### 用户输入:"分析张三"
|
|||
|
|
|
|||
|
|
1. **AI意图识别**
|
|||
|
|
- 调用`parseUserIntentWithAI("分析张三")`
|
|||
|
|
- AI返回:
|
|||
|
|
```json
|
|||
|
|
{
|
|||
|
|
"action": "analyzeReport",
|
|||
|
|
"params": {
|
|||
|
|
"keyword": "张三"
|
|||
|
|
},
|
|||
|
|
"confidence": 0.9,
|
|||
|
|
"reasoning": "用户想分析张三的测评报告"
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
2. **执行意图**
|
|||
|
|
- 调用`executeAIIntent(intent)`
|
|||
|
|
- 识别为分析类指令,返回`false`继续处理
|
|||
|
|
- 保存`aiRecognizedIntent = intent`
|
|||
|
|
|
|||
|
|
3. **获取报告数据**
|
|||
|
|
- 检测到`aiRecognizedIntent`存在
|
|||
|
|
- 提取参数:`reportKeyword = "张三"`
|
|||
|
|
- 调用`getStudentOptions({ keyword: "张三", limit: 1 })`获取用户ID
|
|||
|
|
- 调用`listReport({ userId })`获取报告列表
|
|||
|
|
- 调用`getReport(reportId)`获取报告详情
|
|||
|
|
|
|||
|
|
4. **AI分析报告**
|
|||
|
|
- 将报告数据作为context传递给AI
|
|||
|
|
- AI分析报告内容并返回分析结果
|
|||
|
|
- 在对话框中显示AI的分析结果
|
|||
|
|
|
|||
|
|
## 指令类型区分
|
|||
|
|
|
|||
|
|
### analyzeReport(分析报告)
|
|||
|
|
- 关键词:分析、数据、报告
|
|||
|
|
- 示例:
|
|||
|
|
- "分析张三的报告"
|
|||
|
|
- "分析李四的数据"
|
|||
|
|
- "分析报告123"
|
|||
|
|
- 行为:获取报告数据 → AI分析 → 返回分析结果
|
|||
|
|
|
|||
|
|
### analyzeProfile(查看画像)
|
|||
|
|
- 关键词:画像、档案、情况、了解
|
|||
|
|
- 示例:
|
|||
|
|
- "查看王五的画像"
|
|||
|
|
- "了解赵六的情况"
|
|||
|
|
- "打开张三的档案"
|
|||
|
|
- 行为:跳转到个体画像页面
|
|||
|
|
|
|||
|
|
### goReport(打开报告)
|
|||
|
|
- 关键词:打开、查看
|
|||
|
|
- 示例:
|
|||
|
|
- "打开张三的报告"
|
|||
|
|
- "查看报告列表"
|
|||
|
|
- 行为:跳转到报告列表页面
|
|||
|
|
|
|||
|
|
## 修改文件
|
|||
|
|
- `xinlidsj/pages/index/index.vue`
|
|||
|
|
- 第1605-1625行:保存AI识别的意图
|
|||
|
|
- 第1710-1740行:优先使用AI识别的参数
|
|||
|
|
|
|||
|
|
## 测试建议
|
|||
|
|
1. 测试AI识别:"分析张三" → 应该获取张三的报告并让AI分析
|
|||
|
|
2. 测试正则回退:关闭AI意图识别 → 应该使用正则匹配
|
|||
|
|
3. 测试不同指令:
|
|||
|
|
- "分析李四的数据" → analyzeReport
|
|||
|
|
- "查看王五的画像" → analyzeProfile(跳转页面)
|
|||
|
|
- "打开赵六的报告" → goReport(跳转页面)
|
|||
|
|
4. 测试错误处理:
|
|||
|
|
- 用户不存在 → "没有查询到相关数据"
|
|||
|
|
- 用户无报告 → "没有查询到相关数据"
|
|||
|
|
|
|||
|
|
## 日志输出
|
|||
|
|
关键日志点:
|
|||
|
|
- `尝试AI意图识别...`
|
|||
|
|
- `AI识别到意图: {action, params, confidence}`
|
|||
|
|
- `分析类指令,保存AI识别的参数: {...}`
|
|||
|
|
- `使用AI识别的参数: {keyword: "张三"}`
|
|||
|
|
- `最终使用的参数 - reportId: "", reportKeyword: "张三", profileKeyword: ""`
|
|||
|
|
|
|||
|
|
通过这些日志可以追踪整个流程,确认AI识别和参数传递是否正常。
|