From 24945d62bc57ed05cf0137af8a18d8cadb2cc102 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=A3=E4=B8=87=E4=BF=8A?= Date: Tue, 2 Sep 2025 17:01:48 +0800 Subject: [PATCH] =?UTF-8?q?fix/=E4=BC=98=E5=8C=96=E6=8C=87=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config/index.js | 15 ----- src/view/components/projectModal.vue | 2 +- src/view/components/speechControl.vue | 88 +++++++++++++++++---------- 3 files changed, 58 insertions(+), 47 deletions(-) diff --git a/src/config/index.js b/src/config/index.js index 677c3ca..dd807c3 100644 --- a/src/config/index.js +++ b/src/config/index.js @@ -61,7 +61,6 @@ const config = { params: [], isIframe: true, children: [ - // 用于测试搜索设备管理列表 { command: "search_project", description: "设备名称 设备搜索 搜索设备", @@ -186,20 +185,6 @@ const config = { params: [], isIframe: true, }, - - { - command: "input_project_name", - description: "搜索项目", - action: "input", - selector: "#ai-speech-project-name", - params: [ - { - name: "projectname", - type: "string", - description: "输入项目名称", - }, - ], - }, { command: "close_build_project", description: "取消", diff --git a/src/view/components/projectModal.vue b/src/view/components/projectModal.vue index 34df6a7..38d5b44 100644 --- a/src/view/components/projectModal.vue +++ b/src/view/components/projectModal.vue @@ -293,7 +293,7 @@
- 取消 + 取消 创建项目
diff --git a/src/view/components/speechControl.vue b/src/view/components/speechControl.vue index 87f2ba2..48507b4 100644 --- a/src/view/components/speechControl.vue +++ b/src/view/components/speechControl.vue @@ -62,9 +62,6 @@ import { ref, onMounted, watch, nextTick } from "vue"; import config from "./../../config/index"; -console.log(config,"-====config"); - - const listenStatus = ref(false); const props = defineProps({ @@ -109,7 +106,7 @@ class VoiceControl { // 音频处理参数(重要) this.recognition.energy_threshold = 500; // 能量阈值 - this.recognition.pause_threshold = 0.3; // 停顿时间阈值(秒) + this.recognition.pause_threshold = 0.5; // 停顿时间阈值(秒) this.recognition.phrase_threshold = 0.2; // 短语识别阈值 this.lastFinalTranscript = ""; // 用于跟踪最终结果 @@ -227,28 +224,61 @@ class VoiceControl { } const prompt = ` - 你是一个网页控制助手。请根据以下配置文件,分析用户自然语言请求,从可用指令集中筛选出与请求意图匹配的指令,将用户的自然语言指令解析成一个可执行的指令序列。 - - 配置文件: - ${JSON.stringify(this.config, null, 2)} - - 用户指令:"${userQuery}" - - 请严格按照以下JSON格式输出,只包含一个名为"sequence"的数组: - { "sequence": [ { "command": "command_name", "params": { "param_name": "value" } }, ... ] } - - 要求: - 1. 只使用配置文件中定义的command - 2.按照符合逻辑的执行顺序对筛选出的指令进行排序(例如:登录需遵循 "打开登录→输入用户名→输入密码→提交登录" 的顺序) - 3.仅保留指令的 command 字段,形成有序数组 - 4.若是command的children符合指令,则父指令也输出。比如: 输入人员管理,人员管理处于智能运维的children子菜单,则输出两条指令为智能运维→人员管理。 - 5. 如果用户指令中包含参数值(如用户名、密码、关键词),请正确提取并填充到params中 - 6.若请求涉及多个独立操作,需按操作逻辑拆分排序(如 "先登录再搜索商品" 需包含两部分完整指令链) - 7.严格禁止添加指令集中不存在的指令,无关指令需排除 - 8.若无可匹配指令,返回空数组 - - 现在请生成针对"${userQuery}"的JSON指令序列: - `; + 你是一个网页控制助手,负责将用户的自然语言指令转换为可执行的指令序列。请基于提供的配置信息,分析用户请求的意图,从可用指令集中精准匹配相应指令。 + + # 配置信息 + ${JSON.stringify(this.config, null, 2)} + + # 用户指令 + "${userQuery}" + + # 输出要求 + 请严格按照以下JSON格式输出,只包含名为"sequence"的数组: + { "sequence": [ { "command": "command_name", "params": { "param_name": "value" } } ] } + + # 处理规则 + 1. **指令匹配**:仅使用配置文件中明确定义的指令,禁止添加任何额外指令 + 2. **执行顺序**:按照逻辑顺序排列指令(如:"打开页面→输入信息→提交操作") + 3. **层级处理**:若子指令被匹配,必须包含其父指令以形成完整路径(如:智能运维→人员管理) + 4. **参数提取**:从用户指令中准确提取参数值并填充到对应字段 + 5. **多操作处理**:复合指令需拆分为多个完整操作序列并按逻辑排序 + 6. **语音容错**:对可能的语音识别错误(特别是专有名词)进行智能矫正 + 7. **场景判断**:根据关键词自动判断场景(设备相关→搜索设备,人员相关→搜索人员等) + 8. **默认处理**:无匹配指令时返回空数组 + + # 特别注意 + - 针对语音识别可能出现的同音词错误,使用上下文智能矫正(如:"疯了"→"风冷") + - 参数值提取时保持原始语义准确性 + - 确保输出为纯JSON格式,无额外解释内容 + + 请生成针对"${userQuery}"的指令序列: + `; + + // const prompt = ` + // 你是一个网页控制助手。请根据以下配置文件,分析用户自然语言请求,从可用指令集中筛选出与请求意图匹配的指令,将用户的自然语言指令解析成一个可执行的指令序列。 + + // 配置文件: + // ${JSON.stringify(this.config, null, 2)} + + // 用户指令:"${userQuery}" + + // 请严格按照以下JSON格式输出,只包含一个名为"sequence"的数组: + // { "sequence": [ { "command": "command_name", "params": { "param_name": "value" } }, ... ] } + + // 要求: + // 1. 只使用配置文件中定义的command + // 2.按照符合逻辑的执行顺序对筛选出的指令进行排序(例如:登录需遵循 "打开登录→输入用户名→输入密码→提交登录" 的顺序) + // 3.仅保留指令的 command 字段,形成有序数组 + // 4.若是command的children符合指令,则父指令也输出。比如: 输入人员管理,人员管理处于智能运维的children子菜单,则输出两条指令为智能运维→人员管理。 + // 5. 如果用户指令中包含参数值(如用户名、密码、关键词),请正确提取并填充到params中 + // 6.若请求涉及多个独立操作,需按操作逻辑拆分排序(如 "先登录再搜索商品" 需包含两部分完整指令链) + // 7.严格禁止添加指令集中不存在的指令,无关指令需排除 + // 8.若无可匹配指令,返回空数组 + // 9.因为语音识别的问题,有的关键词可能是专有名词的原因没有识别正确,比如语音输入风冷,结果被识别成疯了,封了等。可能是设备或者专有名词,根据同音尽量矫正。 + // 10.对于带有关键词的根据关键词智能判断场景,比如关键词是设备相关则是搜索设备,关键词是人物相关则是搜索人员等。 + + // 现在请生成针对"${userQuery}"的JSON指令序列: + // `; const response = await fetch( "https://api.deepseek.com/v1/chat/completions", @@ -326,8 +356,6 @@ class VoiceControl { async executeSequence(sequence) { for (const [index, instruction] of sequence.sequence.entries()) { - console.log(instruction, "-----instruction"); - try { await this.executeInstruction(instruction); @@ -402,7 +430,7 @@ class VoiceControl { instruction.command ); - console.log(instruction, commandConfig, "----commandConfig"); + console.log(commandConfig, "===> commandConfig"); if (!commandConfig) { throw new Error(`未知指令: ${instruction.command}`); @@ -420,8 +448,6 @@ class VoiceControl { const element = document.querySelector(commandConfig.selector); - console.log(element, "====> 控制元素"); - if (!element) { throw new Error(`找不到元素: ${commandConfig.selector}`); }