完成“获取智能体模板”

This commit is contained in:
CGD
2025-03-28 11:20:08 +08:00
parent 97b777f1b2
commit 00a0b26797
3 changed files with 128 additions and 81 deletions
+20 -6
View File
@@ -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();
},
// 新增方法:获取智能体模板
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(); }).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;
+43 -7
View File
@@ -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,7 +103,6 @@ export default {
components: {HeaderBar}, components: {HeaderBar},
data() { data() {
return { return {
deviceMac: 'CC:ba:97:11:a6:ac',
form: { form: {
agentCode: "", agentCode: "",
agentName: "", agentName: "",
@@ -133,7 +132,8 @@ export default {
{label: '意图识别模型(Intent)', key: 'intentModelId'}, {label: '意图识别模型(Intent)', key: 'intentModelId'},
{label: '记忆模型(Memory)', key: 'memModelId'} {label: '记忆模型(Memory)', key: 'memModelId'}
], ],
templates: ['台湾女友', '土豆子', '英语老师', '好奇小男孩', '汪汪队队长'] templates: ['台湾女友', '土豆子', '英语老师', '好奇小男孩', '汪汪队队长'],
loadingTemplate: false
} }
}, },
methods: { methods: {
@@ -191,9 +191,45 @@ export default {
}).catch(() => { }).catch(() => {
}) })
}, },
selectTemplate(template) { selectTemplate(templateName) {
this.form.name = template; if (this.loadingTemplate) return;
this.$message.success(`已选择模板:${template}`);
this.loadingTemplate = true;
import('@/apis/module/user').then(({default: userApi}) => {
userApi.getAgentTemplate(
{templateName},
(response) => {
this.loadingTemplate = false;
if (response.data.code === 0 && response.data.data.length > 0) {
this.applyTemplateData(response.data.data[0]);
this.$message.success(`${templateName}」模板已应用`);
} else {
this.$message.warning(`未找到「${templateName}」模板`);
}
}
);
}).catch((error) => {
this.loadingTemplate = false;
this.$message.error('模板加载失败');
console.error('接口异常:', error);
});
},
applyTemplateData(templateData) {
this.form = {
...this.form,
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) { fetchAgentConfig(agentId) {
import('@/apis/module/user').then(({default: userApi}) => { import('@/apis/module/user').then(({default: userApi}) => {