mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-22 15:13:55 +08:00
完善并调试智能体接口配置
This commit is contained in:
@@ -3,7 +3,6 @@ import {getServiceUrl} from '../api'
|
||||
|
||||
|
||||
export default {
|
||||
|
||||
// 获取智能体列表
|
||||
getAgentList(callback) {
|
||||
RequestService.sendRequest()
|
||||
@@ -19,13 +18,12 @@ export default {
|
||||
});
|
||||
}).send();
|
||||
},
|
||||
|
||||
// 添加智能体
|
||||
addAgent(agentName, callback) {
|
||||
RequestService.sendRequest()
|
||||
.url(`${getServiceUrl()}/api/v1/agent/add`)
|
||||
.url(`${getServiceUrl()}/api/v1/agent`)
|
||||
.method('POST')
|
||||
.data({name: agentName})
|
||||
.data({agentName: agentName})
|
||||
.success((res) => {
|
||||
RequestService.clearRequestTime();
|
||||
callback(res);
|
||||
@@ -51,7 +49,6 @@ export default {
|
||||
});
|
||||
}).send();
|
||||
},
|
||||
|
||||
// 获取智能体配置
|
||||
getDeviceConfig(deviceId, callback) {
|
||||
RequestService.sendRequest()
|
||||
@@ -85,9 +82,9 @@ export default {
|
||||
}).send();
|
||||
},
|
||||
// 新增方法:获取智能体模板
|
||||
getAgentTemplate(templateName, callback) {
|
||||
getAgentTemplate(callback) { // 移除templateName参数
|
||||
RequestService.sendRequest()
|
||||
.url(`${getServiceUrl()}/api/v1/agent/templateId`)
|
||||
.url(`${getServiceUrl()}/api/v1/agent/template`)
|
||||
.method('GET')
|
||||
.success((res) => {
|
||||
RequestService.clearRequestTime();
|
||||
@@ -96,8 +93,8 @@ export default {
|
||||
.fail((err) => {
|
||||
console.error('获取模板失败:', err);
|
||||
RequestService.reAjaxFun(() => {
|
||||
this.getAgentTemplate(templateName, callback);
|
||||
this.getAgentTemplate(callback);
|
||||
});
|
||||
}).send();
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<div style="width: 40px;height: 40px;border-radius: 50%;background: #5778ff;display: flex;align-items: center;justify-content: center;">
|
||||
<img loading="lazy" src="@/assets/home/equipment.png" alt="" style="width: 18px;height: 15px;" />
|
||||
</div>
|
||||
添加智慧体
|
||||
添加智能体
|
||||
</div>
|
||||
<div style="height: 1px;background: #e8f0ff;" />
|
||||
<div style="margin: 22px 15px;">
|
||||
@@ -12,7 +12,7 @@
|
||||
<div style="color: red;display: inline-block;">*</div> 智慧体名称:
|
||||
</div>
|
||||
<div class="input-46" style="margin-top: 12px;">
|
||||
<el-input placeholder="请输入智慧体名称.." v-model="wisdomBodyName" />
|
||||
<el-input placeholder="请输入智能体名称.." v-model="wisdomBodyName" />
|
||||
</div>
|
||||
</div>
|
||||
<div style="display: flex;margin: 15px 15px;gap: 7px;">
|
||||
@@ -29,7 +29,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import userApi from '@/apis/module/user';
|
||||
import userApi from '@/apis/module/agent';
|
||||
|
||||
|
||||
export default {
|
||||
@@ -43,7 +43,7 @@ export default {
|
||||
methods: {
|
||||
confirm() {
|
||||
if (!this.wisdomBodyName.trim()) {
|
||||
this.$message.error('请输入智慧体名称');
|
||||
this.$message.error('请输入智能体名称');
|
||||
return;
|
||||
}
|
||||
userApi.addAgent(this.wisdomBodyName, (res) => {
|
||||
|
||||
@@ -106,7 +106,7 @@ export default {
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(() => {
|
||||
import('@/apis/module/user').then(({ default: userApi }) => {
|
||||
import('@/apis/module/agent').then(({ default: userApi }) => {
|
||||
userApi.deleteAgent(agentId, (res) => {
|
||||
if (res.data.code === 0) {
|
||||
this.$message.success('删除成功');
|
||||
|
||||
@@ -59,7 +59,7 @@
|
||||
清除
|
||||
</div>
|
||||
</div>
|
||||
<div style="color: #979db1;font-size:11px;">{{ form.langCode.length }}/1000</div>
|
||||
<div style="color: #979db1;font-size:11px;">{{ (form.langCode || '').length }}/1000</div>
|
||||
</div>
|
||||
</div>
|
||||
</el-form-item>
|
||||
@@ -132,7 +132,7 @@ export default {
|
||||
{label: '意图识别模型(Intent)', key: 'intentModelId'},
|
||||
{label: '记忆模型(Memory)', key: 'memModelId'}
|
||||
],
|
||||
templates: ['台湾女友', '土豆子', '英语老师', '好奇小男孩', '汪汪队队长'],
|
||||
templates: ['湾湾小何', '星际游子', '英语老师', '好奇男孩', '汪汪队长'],
|
||||
loadingTemplate: false
|
||||
}
|
||||
},
|
||||
@@ -153,8 +153,8 @@ export default {
|
||||
language: this.form.language,
|
||||
sort: this.form.sort
|
||||
};
|
||||
import('@/apis/module/user').then(({default: userApi}) => {
|
||||
userApi.updateAgentConfig(this.$route.query.agentId, configData, ({data}) => {
|
||||
import('@/apis/module/agent').then(({default: agentApi}) => {
|
||||
agentApi.updateAgentConfig(this.$route.query.agentId, configData, ({data}) => {
|
||||
if (data.code === 0) {
|
||||
this.$message.success('配置保存成功');
|
||||
} else {
|
||||
@@ -192,27 +192,31 @@ export default {
|
||||
})
|
||||
},
|
||||
selectTemplate(templateName) {
|
||||
if (this.loadingTemplate) return;
|
||||
|
||||
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);
|
||||
});
|
||||
if (this.loadingTemplate) return;
|
||||
this.loadingTemplate = true;
|
||||
import('@/apis/module/agent').then(({default: agentApi}) => {
|
||||
agentApi.getAgentTemplate((response) => { // 移除参数传递
|
||||
this.loadingTemplate = false;
|
||||
if (response.data.code === 0) {
|
||||
// 在客户端过滤匹配的模板
|
||||
const matchedTemplate = response.data.data.find(
|
||||
t => t.agentName === templateName
|
||||
);
|
||||
if (matchedTemplate) {
|
||||
this.applyTemplateData(matchedTemplate);
|
||||
this.$message.success(`「${templateName}」模板已应用`);
|
||||
} else {
|
||||
this.$message.warning(`未找到「${templateName}」模板`);
|
||||
}
|
||||
} else {
|
||||
this.$message.error(response.data.msg || '获取模板失败');
|
||||
}
|
||||
});
|
||||
}).catch((error) => {
|
||||
this.loadingTemplate = false;
|
||||
this.$message.error('模板加载失败');
|
||||
console.error('接口异常:', error);
|
||||
});
|
||||
},
|
||||
applyTemplateData(templateData) {
|
||||
this.form = {
|
||||
@@ -232,8 +236,8 @@ export default {
|
||||
};
|
||||
},
|
||||
fetchAgentConfig(agentId) {
|
||||
import('@/apis/module/user').then(({default: userApi}) => {
|
||||
userApi.getDeviceConfig(agentId, ({data}) => {
|
||||
import('@/apis/module/agent').then(({default: agentApi}) => {
|
||||
agentApi.getDeviceConfig(agentId, ({data}) => {
|
||||
if (data.code === 0) {
|
||||
this.form = {
|
||||
...this.form,
|
||||
|
||||
Reference in New Issue
Block a user