fix/优化指令

This commit is contained in:
季万俊 2025-09-02 17:01:48 +08:00
parent dd6a0f6155
commit 24945d62bc
3 changed files with 58 additions and 47 deletions

View File

@ -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: "取消",

View File

@ -293,7 +293,7 @@
<el-input v-model="projectName" id="ai-speech-project-name" placeholder="请输入名称" />
</div>
<div class="FootBtn">
<el-button class="close-btn" @click="handleClose">取消</el-button>
<el-button id="ai-speech-close_buildproject" class="close-btn" @click="handleClose">取消</el-button>
<el-button id="ai-speech-buildproject" type="primary" @click="submitFun">创建项目</el-button>
</div>
</div>

View File

@ -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.commandchildren: 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}`);
}