|
@@ -129,6 +129,33 @@
|
|
|
</el-col>
|
|
|
</el-row>
|
|
|
<el-row :gutter="24">
|
|
|
+ <el-col :span="12">
|
|
|
+ <el-form-item label="应用图标:">
|
|
|
+ <!-- aiagent_icon -->
|
|
|
+ <el-upload
|
|
|
+ class="avatar-uploader"
|
|
|
+ :action="uploadUrl"
|
|
|
+ method="post"
|
|
|
+ :data="params"
|
|
|
+ :show-file-list="false"
|
|
|
+ :on-success="onUploadAddSuccess"
|
|
|
+ >
|
|
|
+ <img
|
|
|
+ v-if="
|
|
|
+ AIform.aiagent_icon != null && AIform.aiagent_icon != ''
|
|
|
+ "
|
|
|
+ :src="AIform.aiagent_icon"
|
|
|
+ class="avatar"
|
|
|
+ />
|
|
|
+ <i v-else class="el-icon-plus avatar-uploader-icon"></i>
|
|
|
+ <!-- <svg-icon
|
|
|
+ icon-class="header"
|
|
|
+ style="height: 70px; width: 70px"
|
|
|
+ v-else
|
|
|
+ /> -->
|
|
|
+ </el-upload>
|
|
|
+ </el-form-item></el-col
|
|
|
+ >
|
|
|
<el-col :span="12">
|
|
|
<el-form-item label="描 述:">
|
|
|
<el-input
|
|
@@ -547,6 +574,33 @@
|
|
|
</el-col>
|
|
|
</el-row>
|
|
|
<el-row :gutter="24">
|
|
|
+ <el-col :span="12">
|
|
|
+ <el-form-item label="应用图标:">
|
|
|
+ <!-- aiagent_icon -->
|
|
|
+ <el-upload
|
|
|
+ class="avatar-uploader"
|
|
|
+ :action="uploadUrl"
|
|
|
+ method="post"
|
|
|
+ :data="params"
|
|
|
+ :show-file-list="false"
|
|
|
+ :on-success="onUploadEditSuccess"
|
|
|
+ >
|
|
|
+ <img
|
|
|
+ v-if="
|
|
|
+ editForm.aiagent_icon != null && editForm.aiagent_icon != ''
|
|
|
+ "
|
|
|
+ :src="editForm.aiagent_icon"
|
|
|
+ class="avatar"
|
|
|
+ />
|
|
|
+ <i v-else class="el-icon-plus avatar-uploader-icon"></i>
|
|
|
+ <!-- <svg-icon
|
|
|
+ icon-class="header"
|
|
|
+ style="height: 70px; width: 70px"
|
|
|
+ v-else
|
|
|
+ /> -->
|
|
|
+ </el-upload>
|
|
|
+ </el-form-item></el-col
|
|
|
+ >
|
|
|
<el-col :span="12">
|
|
|
<el-form-item label="描 述:">
|
|
|
<el-input
|
|
@@ -960,6 +1014,34 @@
|
|
|
</el-col>
|
|
|
</el-row>
|
|
|
<el-row :gutter="24">
|
|
|
+ <el-col :span="12">
|
|
|
+ <el-form-item label="应用图标:">
|
|
|
+ <!-- aiagent_icon -->
|
|
|
+ <el-upload
|
|
|
+ disabled
|
|
|
+ class="avatar-uploader"
|
|
|
+ :action="uploadUrl"
|
|
|
+ method="post"
|
|
|
+ :data="params"
|
|
|
+ :show-file-list="false"
|
|
|
+ :on-success="onUploadEditSuccess"
|
|
|
+ >
|
|
|
+ <img
|
|
|
+ v-if="
|
|
|
+ viewForm.aiagent_icon != null && viewForm.aiagent_icon != ''
|
|
|
+ "
|
|
|
+ :src="viewForm.aiagent_icon"
|
|
|
+ class="avatar"
|
|
|
+ />
|
|
|
+ <i v-else class="el-icon-plus avatar-uploader-icon"></i>
|
|
|
+ <!-- <svg-icon
|
|
|
+ icon-class="header"
|
|
|
+ style="height: 70px; width: 70px"
|
|
|
+ v-else
|
|
|
+ /> -->
|
|
|
+ </el-upload>
|
|
|
+ </el-form-item></el-col
|
|
|
+ >
|
|
|
<el-col :span="12">
|
|
|
<el-form-item label="描 述:">
|
|
|
<el-input
|
|
@@ -1318,10 +1400,12 @@ export default {
|
|
|
role_description: "",
|
|
|
role_permissions: "",
|
|
|
custom_variables: "",
|
|
|
- custom_prompt: "使用以下上下文来回答问题。如果你不知道答案,就说你不知道,不要试图编造答案。上下文: {context} 人类: {question}AI助手: 让我根据提供的上下文来回答你的问题。{custom_greeting}",
|
|
|
+ custom_prompt:
|
|
|
+ "使用以下上下文来回答问题。如果你不知道答案,就说你不知道,不要试图编造答案。上下文: {context} 人类: {question}AI助手: 让我根据提供的上下文来回答你的问题。{custom_greeting}",
|
|
|
application_type: "",
|
|
|
is_default: false,
|
|
|
generate_new_api_key: true,
|
|
|
+ aiagent_icon: "",
|
|
|
},
|
|
|
/* 模型库 */
|
|
|
modelList: [],
|
|
@@ -1384,7 +1468,8 @@ export default {
|
|
|
role_description: "",
|
|
|
role_permissions: "",
|
|
|
custom_variables: "",
|
|
|
- custom_prompt: "使用以下上下文来回答问题。如果你不知道答案,就说你不知道,不要试图编造答案。上下文: {context} 人类: {question}AI助手: 让我根据提供的上下文来回答你的问题。{custom_greeting}",
|
|
|
+ custom_prompt:
|
|
|
+ "使用以下上下文来回答问题。如果你不知道答案,就说你不知道,不要试图编造答案。上下文: {context} 人类: {question}AI助手: 让我根据提供的上下文来回答你的问题。{custom_greeting}",
|
|
|
application_type: "",
|
|
|
is_default: false,
|
|
|
generate_new_api_key: true,
|
|
@@ -1416,11 +1501,17 @@ export default {
|
|
|
role_description: "",
|
|
|
role_permissions: "",
|
|
|
custom_variables: "",
|
|
|
- custom_prompt: "使用以下上下文来回答问题。如果你不知道答案,就说你不知道,不要试图编造答案。上下文: {context} 人类: {question}AI助手: 让我根据提供的上下文来回答你的问题。{custom_greeting}",
|
|
|
+ custom_prompt:
|
|
|
+ "使用以下上下文来回答问题。如果你不知道答案,就说你不知道,不要试图编造答案。上下文: {context} 人类: {question}AI助手: 让我根据提供的上下文来回答你的问题。{custom_greeting}",
|
|
|
application_type: "",
|
|
|
is_default: false,
|
|
|
generate_new_api_key: true,
|
|
|
+ aiagent_icon: "",
|
|
|
+ },
|
|
|
+ params: {
|
|
|
+ token: "",
|
|
|
},
|
|
|
+ uploadUrl: "",
|
|
|
};
|
|
|
},
|
|
|
|
|
@@ -1461,8 +1552,14 @@ export default {
|
|
|
* el 被新创建的 vm.$ el 替换,并挂载到实例上去之后调用该钩子。
|
|
|
* 如果 root 实例挂载了一个文档内元素,当 mounted 被调用时 vm.$ el 也在文档内。
|
|
|
*/
|
|
|
+ created() {
|
|
|
+ let _this = this;
|
|
|
+ _this.uploadUrl = process.env.VUE_APP_BASE_API + "/upload/file";
|
|
|
+ _this.params.token = _this.$store.getters.token;
|
|
|
+ },
|
|
|
mounted() {
|
|
|
/* 初始化列表 */
|
|
|
+
|
|
|
this.init();
|
|
|
this.type = this.$route.query.type;
|
|
|
this.id = this.$route.query.id;
|
|
@@ -1477,6 +1574,10 @@ export default {
|
|
|
/*组件方法*/
|
|
|
methods: {
|
|
|
/* 编辑 */
|
|
|
+ /* 上传图标 */
|
|
|
+ onUploadEditSuccess(e) {
|
|
|
+ this.editForm.aiagent_icon = e.data.fileUrl;
|
|
|
+ },
|
|
|
handleEditDocumentChange(selectedValues) {
|
|
|
if (selectedValues.includes("all")) {
|
|
|
// 如果选择了"全部",则清空其他选项
|
|
@@ -1571,15 +1672,7 @@ export default {
|
|
|
let totalDocuments = 0;
|
|
|
let otherFolderCount = 0;
|
|
|
|
|
|
- for (const kbName of val) {
|
|
|
- // 根据知识库名称找到对应的 ID
|
|
|
- const kbId = this.kneList.find((kb) => kb.name === kbName)?.id;
|
|
|
-
|
|
|
- /* if (!kbId) {
|
|
|
- console.error(`No matching knowledge base found for name: ${kbName}`);
|
|
|
- continue;
|
|
|
- } */
|
|
|
-
|
|
|
+ const promises = val.map(async (kbName) => {
|
|
|
const typeForm = {
|
|
|
page: 1,
|
|
|
pageSize: 9999,
|
|
@@ -1603,17 +1696,21 @@ export default {
|
|
|
}
|
|
|
} catch (error) {
|
|
|
console.error(
|
|
|
- `Error loading directory list for kb_id ${kbId}:`,
|
|
|
+ `Error loading directory list for kb_id ${kbName}:`,
|
|
|
error
|
|
|
);
|
|
|
}
|
|
|
- }
|
|
|
+ });
|
|
|
+
|
|
|
+ await Promise.all(promises);
|
|
|
|
|
|
this.editDirectoryList.unshift({
|
|
|
id: "001",
|
|
|
name: "全部",
|
|
|
document_count: totalDocuments + otherFolderCount,
|
|
|
});
|
|
|
+
|
|
|
+ return this.editDirectoryList;
|
|
|
},
|
|
|
/* 监听目录选择 */
|
|
|
loadEditDocumentList(val) {
|
|
@@ -1639,8 +1736,9 @@ export default {
|
|
|
: this.getDirectoryIdByName(selectedDirectoryName),
|
|
|
};
|
|
|
|
|
|
- getBucketContents(queryForm).then((res) => {
|
|
|
+ return getBucketContents(queryForm).then((res) => {
|
|
|
this.editDocumentList = res.data.documents;
|
|
|
+ return this.editDocumentList;
|
|
|
});
|
|
|
},
|
|
|
// 添加一个辅助方法来根据目录名称获取目录ID
|
|
@@ -1652,6 +1750,10 @@ export default {
|
|
|
},
|
|
|
|
|
|
/* 新增 */
|
|
|
+ /* 上传图片 */
|
|
|
+ onUploadAddSuccess(e) {
|
|
|
+ this.AIform.aiagent_icon = e.data.fileUrl;
|
|
|
+ },
|
|
|
/* 重置表单 */
|
|
|
resetForm() {
|
|
|
if (this.$refs.AIformRef) {
|
|
@@ -1680,10 +1782,12 @@ export default {
|
|
|
role_description: "",
|
|
|
role_permissions: "",
|
|
|
custom_variables: "",
|
|
|
- custom_prompt: "使用以下上下文来回答问题。如果你不知道答案,就说你不知道,不要试图编造答案。上下文: {context} 人类: {question}AI助手: 让我根据提供的上下文来回答你的问题。{custom_greeting}",
|
|
|
+ custom_prompt:
|
|
|
+ "使用以下上下文来回答问题。如果你不知道答案,就说你不知道,不要试图编造答案。上下文: {context} 人类: {question}AI助手: 让我根据提供的上下文来回答你的问题。{custom_greeting}",
|
|
|
application_type: "",
|
|
|
is_default: false,
|
|
|
generate_new_api_key: true,
|
|
|
+ aiagent_icon: "",
|
|
|
};
|
|
|
},
|
|
|
/* 取消 */
|
|
@@ -1920,16 +2024,53 @@ export default {
|
|
|
},
|
|
|
/* 编辑查看 */
|
|
|
initEdit() {
|
|
|
- // 根据 card 的数据填充 editForm
|
|
|
- this.editForm = JSON.parse(JSON.stringify(this.$route.query.card)); // 深拷贝以避免直接修改原对象
|
|
|
+ // 深拷贝以避免直接修改原对象
|
|
|
+ this.editForm = JSON.parse(JSON.stringify(this.$route.query.card));
|
|
|
|
|
|
- // 处理 knowledge_base_names
|
|
|
- /* this.editForm.knowledge_base_names =
|
|
|
- this.editForm.knowledge_base_names.map((name) => {
|
|
|
- const kb = this.kneList.find((kb) => kb.name == name);
|
|
|
- console.log(this.kneList);
|
|
|
- return kb ? kb.id : name; // 如果找不到对应的知识库,保留原名称
|
|
|
- }); */
|
|
|
+ // 处理 role_permissions 和 custom_variables
|
|
|
+ this.handleJsonFields();
|
|
|
+
|
|
|
+ // 加载知识库对应的目录列表
|
|
|
+ this.loadEditDirectoryList(this.editForm.knowledge_base_names).then(
|
|
|
+ () => {
|
|
|
+ // 在目录列表加载完成后,设置选中的目录
|
|
|
+ if (
|
|
|
+ this.editForm.document_directories &&
|
|
|
+ this.editForm.document_directories.length > 0
|
|
|
+ ) {
|
|
|
+ const dirId = this.editDirectoryList.find(
|
|
|
+ (dir) => dir.name === this.editForm.document_directories[0]
|
|
|
+ )?.id;
|
|
|
+ if (dirId) {
|
|
|
+ this.editForm.document_directories = dirId;
|
|
|
+ // 加载文档列表
|
|
|
+ this.loadEditDocumentList(dirId).then(() => {
|
|
|
+ this.$nextTick(() => {
|
|
|
+ // 在文档列表加载完成且DOM更新后,设置选中的文档
|
|
|
+ if (
|
|
|
+ !this.editForm.documents ||
|
|
|
+ this.editForm.documents.length === 0
|
|
|
+ ) {
|
|
|
+ // 如果 documents 为空,设置为 "全部"
|
|
|
+ this.editForm.documents = ["all"];
|
|
|
+ } else if (this.editForm.documents.includes("全部")) {
|
|
|
+ this.editForm.documents = ["all"];
|
|
|
+ } else {
|
|
|
+ this.editForm.documents = this.editDocumentList
|
|
|
+ .filter((doc) =>
|
|
|
+ this.editForm.documents.includes(doc.name)
|
|
|
+ )
|
|
|
+ .map((doc) => doc.id);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ );
|
|
|
+ },
|
|
|
+
|
|
|
+ handleJsonFields() {
|
|
|
// 处理 role_permissions
|
|
|
if (this.editForm.role_permissions) {
|
|
|
if (typeof this.editForm.role_permissions !== "string") {
|
|
@@ -1954,37 +2095,6 @@ export default {
|
|
|
} else {
|
|
|
this.editForm.custom_variables = "";
|
|
|
}
|
|
|
-
|
|
|
- // 加载知识库对应的目录列表
|
|
|
- this.loadEditDirectoryList(this.editForm.knowledge_base_names).then(
|
|
|
- () => {
|
|
|
- // 在目录列表加载完成后,设置选中的目录
|
|
|
- if (
|
|
|
- this.editForm.document_directories &&
|
|
|
- this.editForm.document_directories.length > 0
|
|
|
- ) {
|
|
|
- const dirId = this.editDirectoryList.find(
|
|
|
- (dir) => dir.name === this.editForm.document_directories[0]
|
|
|
- )?.id;
|
|
|
- if (dirId) {
|
|
|
- this.editForm.document_directories = dirId;
|
|
|
- // 加载文档列表
|
|
|
- this.loadEditDocumentList(dirId).then(() => {
|
|
|
- // 在文档列表加载完成后,设置选中的文档
|
|
|
- if (
|
|
|
- this.editForm.documents &&
|
|
|
- this.editForm.documents.length > 0
|
|
|
- ) {
|
|
|
- this.editForm.documents = this.editDocumentList
|
|
|
- .filter((doc) => this.editForm.documents.includes(doc.name))
|
|
|
- .map((doc) => doc.id);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- );
|
|
|
- /* this.loadEditDocumentList(this.editForm.document_directories[0]); */
|
|
|
},
|
|
|
/* 查看 */
|
|
|
initView() {
|
|
@@ -2023,6 +2133,20 @@ export default {
|
|
|
this.viewForm.custom_variables = "";
|
|
|
}
|
|
|
|
|
|
+ // 处理文档选择
|
|
|
+ if (
|
|
|
+ !this.viewForm.documents ||
|
|
|
+ this.viewForm.documents.length === 0 ||
|
|
|
+ this.viewForm.documents.includes("全部")
|
|
|
+ ) {
|
|
|
+ this.viewForm.documents = ["全部"];
|
|
|
+ } else {
|
|
|
+ // 将文档名称转换为ID(如果需要的话)
|
|
|
+ this.viewForm.documents = this.viewForm.documents.map((docName) => {
|
|
|
+ const doc = this.editDocumentList.find((d) => d.name === docName);
|
|
|
+ return doc ? doc.id : docName;
|
|
|
+ });
|
|
|
+ }
|
|
|
/* // 处理文档选择
|
|
|
if (this.editForm.documents.length === 0 || this.editForm.documents.includes('全部')) {
|
|
|
this.editForm.documents = ['all'];
|
|
@@ -2060,4 +2184,27 @@ export default {
|
|
|
justify-content: flex-end;
|
|
|
margin: 0 100px 20px;
|
|
|
}
|
|
|
+::v-deep .avatar-uploader .el-upload {
|
|
|
+ border: 1px dashed #d9d9d9;
|
|
|
+ border-radius: 6px;
|
|
|
+ cursor: pointer;
|
|
|
+ position: relative;
|
|
|
+ overflow: hidden;
|
|
|
+}
|
|
|
+.avatar-uploader .el-upload:hover {
|
|
|
+ border-color: #409eff;
|
|
|
+}
|
|
|
+.avatar-uploader-icon {
|
|
|
+ font-size: 28px;
|
|
|
+ color: #8c939d;
|
|
|
+ width: 100px;
|
|
|
+ height: 100px;
|
|
|
+ line-height: 100px;
|
|
|
+ text-align: center;
|
|
|
+}
|
|
|
+.avatar {
|
|
|
+ width: 100px;
|
|
|
+ height: 100px;
|
|
|
+ display: block;
|
|
|
+}
|
|
|
</style>
|