fix: IoT快速通道补充关掉/关上 + 多设备上下文窗口扩展至30字节
- intent_analyzer: isStrongIoTCommand controlWords新增"关掉""关上" - iot_provider: 操作检测上下文窗口±15→±30字节,新增全文回退逻辑 - 修复多设备命令中远处关键词无法匹配导致操作误判为query E2E: "关掉"快速通道2.57s✅ 多设备同时开关✅ 8设备查询✅ Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -230,21 +230,30 @@ func (p *IoTProvider) Execute(ctx context.Context, subCtx []model.LLMMessage) (*
|
||||
continue
|
||||
}
|
||||
|
||||
// 判断此设备的操作:检查设备名附近的意图词
|
||||
// 判断此设备的操作:先检查附近上下文,再回退到全文匹配
|
||||
devIdx := strings.Index(msgLower, devNameLower)
|
||||
contextStart := devIdx - 15
|
||||
contextStart := devIdx - 30
|
||||
if contextStart < 0 {
|
||||
contextStart = 0
|
||||
}
|
||||
contextEnd := devIdx + len(devNameLower) + 15
|
||||
contextEnd := devIdx + len(devNameLower) + 30
|
||||
if contextEnd > len(msgLower) {
|
||||
contextEnd = len(msgLower)
|
||||
}
|
||||
nearbyContext := msgLower[contextStart:contextEnd]
|
||||
|
||||
if strings.Contains(nearbyContext, "打开") || strings.Contains(nearbyContext, "开") {
|
||||
hasOpen := strings.Contains(nearbyContext, "打开") || strings.Contains(nearbyContext, "开")
|
||||
hasClose := strings.Contains(nearbyContext, "关闭") || strings.Contains(nearbyContext, "关掉") || strings.Contains(nearbyContext, "关上") || strings.Contains(nearbyContext, "关")
|
||||
|
||||
// 附近上下文不足以判断时,回退到全文搜索
|
||||
if !hasOpen && !hasClose {
|
||||
hasOpen = strings.Contains(msgLower, "打开")
|
||||
hasClose = strings.Contains(msgLower, "关闭") || strings.Contains(msgLower, "关掉") || strings.Contains(msgLower, "关上")
|
||||
}
|
||||
|
||||
if hasOpen {
|
||||
actions = append(actions, deviceAction{dev: dev, operation: "on"})
|
||||
} else if strings.Contains(nearbyContext, "关闭") || strings.Contains(nearbyContext, "关掉") || strings.Contains(nearbyContext, "关上") {
|
||||
} else if hasClose {
|
||||
actions = append(actions, deviceAction{dev: dev, operation: "off"})
|
||||
} else {
|
||||
actions = append(actions, deviceAction{dev: dev, operation: "query"})
|
||||
|
||||
Reference in New Issue
Block a user