mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-28 01:53:53 +08:00
完成“获取智能体模板”
This commit is contained in:
@@ -186,7 +186,6 @@ export default {
|
|||||||
},
|
},
|
||||||
// 已绑设备
|
// 已绑设备
|
||||||
getAgentBindDevices(agentId, callback) {
|
getAgentBindDevices(agentId, callback) {
|
||||||
console.log("77777777777777777777777")
|
|
||||||
RequestService.sendRequest()
|
RequestService.sendRequest()
|
||||||
.url(`${getServiceUrl()}/api/v1/user/agent/device/bind/${agentId}`)
|
.url(`${getServiceUrl()}/api/v1/user/agent/device/bind/${agentId}`)
|
||||||
.method('GET')
|
.method('GET')
|
||||||
@@ -219,7 +218,6 @@ export default {
|
|||||||
},
|
},
|
||||||
// 绑定设备
|
// 绑定设备
|
||||||
bindDevice(agentId, code, callback) {
|
bindDevice(agentId, code, callback) {
|
||||||
console.log("32323234343434344340000")
|
|
||||||
RequestService.sendRequest()
|
RequestService.sendRequest()
|
||||||
.url(`${getServiceUrl()}/api/v1/user/agent/device/bind/${agentId}`)
|
.url(`${getServiceUrl()}/api/v1/user/agent/device/bind/${agentId}`)
|
||||||
.method('POST')
|
.method('POST')
|
||||||
@@ -229,10 +227,26 @@ export default {
|
|||||||
callback(res);
|
callback(res);
|
||||||
})
|
})
|
||||||
.fail((err) => {
|
.fail((err) => {
|
||||||
// console.error('绑定设备失败:', err);
|
console.error('绑定设备失败:', err);
|
||||||
// RequestService.reAjaxFun(() => {
|
RequestService.reAjaxFun(() => {
|
||||||
// this.bindDevice(agentId, code, callback);
|
this.bindDevice(agentId, code, callback);
|
||||||
// });
|
});
|
||||||
}).send();
|
}).send();
|
||||||
},
|
},
|
||||||
|
// 新增方法:获取智能体模板
|
||||||
|
getAgentTemplate(templateName, callback) {
|
||||||
|
RequestService.sendRequest()
|
||||||
|
.url(`${getServiceUrl()}/api/v1/user/agent/templateId`)
|
||||||
|
.method('GET')
|
||||||
|
.success((res) => {
|
||||||
|
RequestService.clearRequestTime();
|
||||||
|
callback(res);
|
||||||
|
})
|
||||||
|
.fail((err) => {
|
||||||
|
console.error('获取模板失败:', err);
|
||||||
|
RequestService.reAjaxFun(() => {
|
||||||
|
this.getAgentTemplate(templateName, callback);
|
||||||
|
});
|
||||||
|
}).send();
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,9 +44,6 @@ export default {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
confirm() {
|
confirm() {
|
||||||
// console.log(this.agentId)
|
|
||||||
// console.log("=========")
|
|
||||||
// console.log(this.$route.query.agentId)
|
|
||||||
if (!/^\d{6}$/.test(this.deviceCode)) {
|
if (!/^\d{6}$/.test(this.deviceCode)) {
|
||||||
this.$message.error('请输入6位数字验证码');
|
this.$message.error('请输入6位数字验证码');
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
style="width: 37px;height: 37px;background: #5778ff;border-radius: 50%;display: flex;align-items: center;justify-content: center;">
|
style="width: 37px;height: 37px;background: #5778ff;border-radius: 50%;display: flex;align-items: center;justify-content: center;">
|
||||||
<img src="@/assets/home/setting-user.png" alt="" style="width: 19px;height: 19px;"/>
|
<img src="@/assets/home/setting-user.png" alt="" style="width: 19px;height: 19px;"/>
|
||||||
</div>
|
</div>
|
||||||
{{ deviceMac }}
|
{{ form.agentName }}
|
||||||
</div>
|
</div>
|
||||||
<div style="height: 1px;background: #e8f0ff;"/>
|
<div style="height: 1px;background: #e8f0ff;"/>
|
||||||
<el-form ref="form" :model="form" label-width="72px">
|
<el-form ref="form" :model="form" label-width="72px">
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="角色模版:">
|
<el-form-item label="角色模版:">
|
||||||
<div style="display: flex;gap: 8px;">
|
<div style="display: flex;gap: 8px;">
|
||||||
<div v-for="template in templates" :key="template" class="template-item" @click="selectTemplate(template)">
|
<div v-for="template in templates" :key="template" class="template-item" :class="{ 'template-loading': loadingTemplate }" @click="selectTemplate(template)">
|
||||||
{{ template }}
|
{{ template }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -103,65 +103,65 @@ export default {
|
|||||||
components: {HeaderBar},
|
components: {HeaderBar},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
deviceMac: 'CC:ba:97:11:a6:ac',
|
|
||||||
form: {
|
form: {
|
||||||
agentCode:"",
|
agentCode: "",
|
||||||
agentName: "",
|
agentName: "",
|
||||||
ttsVoiceId: "",
|
ttsVoiceId: "",
|
||||||
systemPrompt: "",
|
systemPrompt: "",
|
||||||
langCode:"",
|
langCode: "",
|
||||||
language:"",
|
language: "",
|
||||||
sort:"",
|
sort: "",
|
||||||
model: {
|
model: {
|
||||||
ttsModelId: "",
|
ttsModelId: "",
|
||||||
vadModelId: "",
|
vadModelId: "",
|
||||||
asrModelId:"",
|
asrModelId: "",
|
||||||
llmModelId: "",
|
llmModelId: "",
|
||||||
memModelId: "",
|
memModelId: "",
|
||||||
intentModelId: "",
|
intentModelId: "",
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
options: [
|
options: [
|
||||||
{ value: '选项1', label: '黄金糕' },
|
{value: '选项1', label: '黄金糕'},
|
||||||
{ value: '选项2', label: '双皮奶' }
|
{value: '选项2', label: '双皮奶'}
|
||||||
],
|
],
|
||||||
models: [
|
models: [
|
||||||
{ label: '大语言模型(LLM)', key: 'llmModelId' },
|
{label: '大语言模型(LLM)', key: 'llmModelId'},
|
||||||
{ label: '语音识别(ASR)', key: 'asrModelId' },
|
{label: '语音识别(ASR)', key: 'asrModelId'},
|
||||||
{ label: '语音活动检测模型(VAD)', key: 'vadModelId' },
|
{label: '语音活动检测模型(VAD)', key: 'vadModelId'},
|
||||||
{ label: '语音合成模型(TTS)', key: 'ttsModelId' },
|
{label: '语音合成模型(TTS)', key: 'ttsModelId'},
|
||||||
{ label: '意图识别模型(Intent)', key: 'intentModelId' },
|
{label: '意图识别模型(Intent)', key: 'intentModelId'},
|
||||||
{ label: '记忆模型(Memory)', key: 'memModelId' }
|
{label: '记忆模型(Memory)', key: 'memModelId'}
|
||||||
],
|
],
|
||||||
templates: ['台湾女友', '土豆子', '英语老师', '好奇小男孩', '汪汪队队长']
|
templates: ['台湾女友', '土豆子', '英语老师', '好奇小男孩', '汪汪队队长'],
|
||||||
|
loadingTemplate: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
saveConfig() {
|
saveConfig() {
|
||||||
const configData = {
|
const configData = {
|
||||||
agentCode: this.form.agentCode,
|
agentCode: this.form.agentCode,
|
||||||
agentName: this.form.agentName,
|
agentName: this.form.agentName,
|
||||||
asrModelId: this.form.model.asrModelId,
|
asrModelId: this.form.model.asrModelId,
|
||||||
vadModelId: this.form.model.vadModelId,
|
vadModelId: this.form.model.vadModelId,
|
||||||
llmModelId: this.form.model.llmModelId,
|
llmModelId: this.form.model.llmModelId,
|
||||||
ttsModelId: this.form.model.ttsModelId,
|
ttsModelId: this.form.model.ttsModelId,
|
||||||
ttsVoiceId: this.form.ttsVoiceId,
|
ttsVoiceId: this.form.ttsVoiceId,
|
||||||
memModelId: this.form.model.memModelId,
|
memModelId: this.form.model.memModelId,
|
||||||
intentModelId: this.form.model.intentModelId,
|
intentModelId: this.form.model.intentModelId,
|
||||||
systemPrompt: this.form.systemPrompt,
|
systemPrompt: this.form.systemPrompt,
|
||||||
langCode: this.form.langCode,
|
langCode: this.form.langCode,
|
||||||
language: this.form.language,
|
language: this.form.language,
|
||||||
sort: this.form.sort
|
sort: this.form.sort
|
||||||
};
|
};
|
||||||
import('@/apis/module/user').then(({ default: userApi }) => {
|
import('@/apis/module/user').then(({default: userApi}) => {
|
||||||
userApi.updateAgentConfig(this.$route.query.agentId, configData, ({data}) => {
|
userApi.updateAgentConfig(this.$route.query.agentId, configData, ({data}) => {
|
||||||
if (data.code === 0) {
|
if (data.code === 0) {
|
||||||
this.$message.success('配置保存成功');
|
this.$message.success('配置保存成功');
|
||||||
} else {
|
} else {
|
||||||
this.$message.error(data.msg || '配置保存失败');
|
this.$message.error(data.msg || '配置保存失败');
|
||||||
}
|
}
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
});
|
||||||
},
|
},
|
||||||
resetConfig() {
|
resetConfig() {
|
||||||
this.$confirm('确定要重置配置吗?', '提示', {
|
this.$confirm('确定要重置配置吗?', '提示', {
|
||||||
@@ -171,17 +171,17 @@ export default {
|
|||||||
}).then(() => {
|
}).then(() => {
|
||||||
// 重置表单
|
// 重置表单
|
||||||
this.form = {
|
this.form = {
|
||||||
agentCode:"",
|
agentCode: "",
|
||||||
agentName: "",
|
agentName: "",
|
||||||
ttsVoiceId: "",
|
ttsVoiceId: "",
|
||||||
systemPrompt: "",
|
systemPrompt: "",
|
||||||
langCode:"",
|
langCode: "",
|
||||||
language:"",
|
language: "",
|
||||||
sort:"",
|
sort: "",
|
||||||
model: {
|
model: {
|
||||||
ttsModelId: "",
|
ttsModelId: "",
|
||||||
vadModelId: "",
|
vadModelId: "",
|
||||||
asrModelId:"",
|
asrModelId: "",
|
||||||
llmModelId: "",
|
llmModelId: "",
|
||||||
memModelId: "",
|
memModelId: "",
|
||||||
intentModelId: "",
|
intentModelId: "",
|
||||||
@@ -191,37 +191,73 @@ export default {
|
|||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
selectTemplate(template) {
|
selectTemplate(templateName) {
|
||||||
this.form.name = template;
|
if (this.loadingTemplate) return;
|
||||||
this.$message.success(`已选择模板:${template}`);
|
|
||||||
},
|
this.loadingTemplate = true;
|
||||||
fetchAgentConfig(agentId) {
|
import('@/apis/module/user').then(({default: userApi}) => {
|
||||||
import('@/apis/module/user').then(({ default: userApi }) => {
|
userApi.getAgentTemplate(
|
||||||
userApi.getDeviceConfig(agentId, ({ data }) => {
|
{templateName},
|
||||||
if (data.code === 0) {
|
(response) => {
|
||||||
this.form = {
|
this.loadingTemplate = false;
|
||||||
...this.form,
|
if (response.data.code === 0 && response.data.data.length > 0) {
|
||||||
...data.data,
|
this.applyTemplateData(response.data.data[0]);
|
||||||
model: {
|
this.$message.success(`「${templateName}」模板已应用`);
|
||||||
ttsModelId: data.data.ttsModelId,
|
} else {
|
||||||
vadModelId: data.data.vadModelId,
|
this.$message.warning(`未找到「${templateName}」模板`);
|
||||||
asrModelId: data.data.asrModelId,
|
|
||||||
llmModelId: data.data.llmModelId,
|
|
||||||
memModelId: data.data.memModelId,
|
|
||||||
intentModelId: data.data.intentModelId
|
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
} else {
|
);
|
||||||
this.$message.error(data.msg || '获取配置失败');
|
}).catch((error) => {
|
||||||
}
|
this.loadingTemplate = false;
|
||||||
});
|
this.$message.error('模板加载失败');
|
||||||
|
console.error('接口异常:', error);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
// 清空记忆体内容
|
applyTemplateData(templateData) {
|
||||||
clearMemory() {
|
this.form = {
|
||||||
this.form.langCode = "";
|
...this.form,
|
||||||
this.$message.success("记忆体已清空");
|
agentName: templateData.agentName || this.form.agentName,
|
||||||
|
ttsVoiceId: templateData.ttsVoiceId || this.form.ttsVoiceId,
|
||||||
|
systemPrompt: templateData.systemPrompt || this.form.systemPrompt,
|
||||||
|
langCode: templateData.langCode || this.form.langCode,
|
||||||
|
model: {
|
||||||
|
ttsModelId: templateData.ttsModelId || this.form.model.ttsModelId,
|
||||||
|
vadModelId: templateData.vadModelId || this.form.model.vadModelId,
|
||||||
|
asrModelId: templateData.asrModelId || this.form.model.asrModelId,
|
||||||
|
llmModelId: templateData.llmModelId || this.form.model.llmModelId,
|
||||||
|
memModelId: templateData.memModelId || this.form.model.memModelId,
|
||||||
|
intentModelId: templateData.intentModelId || this.form.model.intentModelId
|
||||||
|
}
|
||||||
|
};
|
||||||
},
|
},
|
||||||
|
fetchAgentConfig(agentId) {
|
||||||
|
import('@/apis/module/user').then(({default: userApi}) => {
|
||||||
|
userApi.getDeviceConfig(agentId, ({data}) => {
|
||||||
|
if (data.code === 0) {
|
||||||
|
this.form = {
|
||||||
|
...this.form,
|
||||||
|
...data.data,
|
||||||
|
model: {
|
||||||
|
ttsModelId: data.data.ttsModelId,
|
||||||
|
vadModelId: data.data.vadModelId,
|
||||||
|
asrModelId: data.data.asrModelId,
|
||||||
|
llmModelId: data.data.llmModelId,
|
||||||
|
memModelId: data.data.memModelId,
|
||||||
|
intentModelId: data.data.intentModelId
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
this.$message.error(data.msg || '获取配置失败');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 清空记忆体内容
|
||||||
|
clearMemory() {
|
||||||
|
this.form.langCode = "";
|
||||||
|
this.$message.success("记忆体已清空");
|
||||||
|
},
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
const agentId = this.$route.query.agentId;
|
const agentId = this.$route.query.agentId;
|
||||||
|
|||||||
Reference in New Issue
Block a user