mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-15 17:30:13 +08:00
新格式导入
This commit is contained in:
@@ -93,7 +93,8 @@
|
||||
"messages": {
|
||||
"moveSuccess": "Persona moved successfully",
|
||||
"moveError": "Failed to move persona",
|
||||
"exportSuccess": "Exported successfully(excluding skills and tools)"
|
||||
"exportSuccess": "Exported successfully(excluding skills and tools)",
|
||||
"importSuccess": "Imported successfully"
|
||||
}
|
||||
},
|
||||
"folder": {
|
||||
|
||||
@@ -93,7 +93,8 @@
|
||||
"messages": {
|
||||
"moveSuccess": "人格移动成功",
|
||||
"moveError": "移动人格失败",
|
||||
"exportSuccess": "导出成功(不包含 Skills 和工具)"
|
||||
"exportSuccess": "导出成功(不包含 Skills 和工具)",
|
||||
"importSuccess": "导入成功"
|
||||
}
|
||||
},
|
||||
"folder": {
|
||||
|
||||
@@ -541,23 +541,36 @@ export default defineComponent({
|
||||
const text = await file.text();
|
||||
const data = JSON.parse(text);
|
||||
|
||||
// 白名单过滤
|
||||
const whitelist = ['persona_id', 'system_prompt', 'begin_dialogs', 'tools', 'skills', 'folder_id'];
|
||||
const filteredData: any = {};
|
||||
let importData: any = {};
|
||||
|
||||
for (const key of whitelist) {
|
||||
if (key in data) {
|
||||
filteredData[key] = data[key];
|
||||
if (data.version && data.persona && Array.isArray(data.persona)) {
|
||||
const firstPersona = data.persona[0];
|
||||
importData = {
|
||||
persona_id: firstPersona.name,
|
||||
system_prompt: firstPersona.prompt,
|
||||
begin_dialogs: []
|
||||
};
|
||||
|
||||
// 转换对话对
|
||||
if (firstPersona.begin_dialogs && Array.isArray(firstPersona.begin_dialogs)) {
|
||||
for (const dialog of firstPersona.begin_dialogs) {
|
||||
if (dialog.user) {
|
||||
importData.begin_dialogs.push(dialog.user);
|
||||
}
|
||||
if (dialog.assistant) {
|
||||
importData.begin_dialogs.push(dialog.assistant);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 验证必需字段
|
||||
if (!filteredData.persona_id || !filteredData.system_prompt) {
|
||||
if (!importData.persona_id || !importData.system_prompt) {
|
||||
throw new Error(this.tm('persona.messages.importMissingFields'));
|
||||
}
|
||||
|
||||
// 执行导入
|
||||
await this.importPersona(filteredData);
|
||||
await this.importPersona(importData);
|
||||
this.showSuccess(this.tm('persona.messages.importSuccess'));
|
||||
} catch (error: any) {
|
||||
console.error(this.tm('persona.messages.importFailed'), error);
|
||||
|
||||
Reference in New Issue
Block a user