|
@@ -115,7 +115,9 @@
|
|
:disabled="isDocumentSelectDisabled"
|
|
:disabled="isDocumentSelectDisabled"
|
|
clearable
|
|
clearable
|
|
filterable
|
|
filterable
|
|
|
|
+ @change="handleDocumentChange"
|
|
>
|
|
>
|
|
|
|
+ <el-option label="全部" value="all"></el-option>
|
|
<el-option
|
|
<el-option
|
|
v-for="(doc, index) in documentList"
|
|
v-for="(doc, index) in documentList"
|
|
:label="doc.name"
|
|
:label="doc.name"
|
|
@@ -274,7 +276,7 @@
|
|
<div class="hint">AI考虑的上下文token数量</div>
|
|
<div class="hint">AI考虑的上下文token数量</div>
|
|
</el-form-item>
|
|
</el-form-item>
|
|
</el-col>
|
|
</el-col>
|
|
- <el-col :span="12">
|
|
|
|
|
|
+ <!-- <el-col :span="12">
|
|
<el-form-item label="会话ID:" prop="session_id">
|
|
<el-form-item label="会话ID:" prop="session_id">
|
|
<el-input
|
|
<el-input
|
|
style="width: 55%"
|
|
style="width: 55%"
|
|
@@ -283,7 +285,7 @@
|
|
></el-input>
|
|
></el-input>
|
|
<div class="hint">特定会话的唯一标识符,如果有的话</div>
|
|
<div class="hint">特定会话的唯一标识符,如果有的话</div>
|
|
</el-form-item>
|
|
</el-form-item>
|
|
- </el-col>
|
|
|
|
|
|
+ </el-col> -->
|
|
</el-row>
|
|
</el-row>
|
|
<el-row :gutter="24">
|
|
<el-row :gutter="24">
|
|
<el-col :span="12">
|
|
<el-col :span="12">
|
|
@@ -531,7 +533,9 @@
|
|
:disabled="editForm.document_directories == ''"
|
|
:disabled="editForm.document_directories == ''"
|
|
clearable
|
|
clearable
|
|
filterable
|
|
filterable
|
|
|
|
+ @change="handleEditDocumentChange"
|
|
>
|
|
>
|
|
|
|
+ <el-option label="全部" value="all"></el-option>
|
|
<el-option
|
|
<el-option
|
|
v-for="(doc, index) in editDocumentList"
|
|
v-for="(doc, index) in editDocumentList"
|
|
:label="doc.name"
|
|
:label="doc.name"
|
|
@@ -690,7 +694,7 @@
|
|
<div class="hint">AI考虑的上下文token数量</div>
|
|
<div class="hint">AI考虑的上下文token数量</div>
|
|
</el-form-item>
|
|
</el-form-item>
|
|
</el-col>
|
|
</el-col>
|
|
- <el-col :span="12">
|
|
|
|
|
|
+ <!-- <el-col :span="12">
|
|
<el-form-item label="会话ID:" prop="session_id">
|
|
<el-form-item label="会话ID:" prop="session_id">
|
|
<el-input
|
|
<el-input
|
|
style="width: 55%"
|
|
style="width: 55%"
|
|
@@ -699,7 +703,7 @@
|
|
></el-input>
|
|
></el-input>
|
|
<div class="hint">特定会话的唯一标识符,如果有的话</div>
|
|
<div class="hint">特定会话的唯一标识符,如果有的话</div>
|
|
</el-form-item>
|
|
</el-form-item>
|
|
- </el-col>
|
|
|
|
|
|
+ </el-col> -->
|
|
</el-row>
|
|
</el-row>
|
|
<el-row :gutter="24">
|
|
<el-row :gutter="24">
|
|
<el-col :span="12">
|
|
<el-col :span="12">
|
|
@@ -1117,7 +1121,7 @@
|
|
<div class="hint">AI考虑的上下文token数量</div>
|
|
<div class="hint">AI考虑的上下文token数量</div>
|
|
</el-form-item>
|
|
</el-form-item>
|
|
</el-col>
|
|
</el-col>
|
|
- <el-col :span="12">
|
|
|
|
|
|
+ <!-- <el-col :span="12">
|
|
<el-form-item label="会话ID:" prop="session_id">
|
|
<el-form-item label="会话ID:" prop="session_id">
|
|
<el-input
|
|
<el-input
|
|
disabled
|
|
disabled
|
|
@@ -1127,7 +1131,7 @@
|
|
></el-input>
|
|
></el-input>
|
|
<div class="hint">特定会话的唯一标识符,如果有的话</div>
|
|
<div class="hint">特定会话的唯一标识符,如果有的话</div>
|
|
</el-form-item>
|
|
</el-form-item>
|
|
- </el-col>
|
|
|
|
|
|
+ </el-col> -->
|
|
</el-row>
|
|
</el-row>
|
|
<el-row :gutter="24">
|
|
<el-row :gutter="24">
|
|
<el-col :span="12">
|
|
<el-col :span="12">
|
|
@@ -1314,7 +1318,7 @@ export default {
|
|
role_description: "",
|
|
role_description: "",
|
|
role_permissions: "",
|
|
role_permissions: "",
|
|
custom_variables: "",
|
|
custom_variables: "",
|
|
- custom_prompt: "",
|
|
|
|
|
|
+ custom_prompt: "使用以下上下文来回答问题。如果你不知道答案,就说你不知道,不要试图编造答案。上下文: {context} 人类: {question}AI助手: 让我根据提供的上下文来回答你的问题。{custom_greeting}",
|
|
application_type: "",
|
|
application_type: "",
|
|
is_default: false,
|
|
is_default: false,
|
|
generate_new_api_key: true,
|
|
generate_new_api_key: true,
|
|
@@ -1380,7 +1384,7 @@ export default {
|
|
role_description: "",
|
|
role_description: "",
|
|
role_permissions: "",
|
|
role_permissions: "",
|
|
custom_variables: "",
|
|
custom_variables: "",
|
|
- custom_prompt: "",
|
|
|
|
|
|
+ custom_prompt: "使用以下上下文来回答问题。如果你不知道答案,就说你不知道,不要试图编造答案。上下文: {context} 人类: {question}AI助手: 让我根据提供的上下文来回答你的问题。{custom_greeting}",
|
|
application_type: "",
|
|
application_type: "",
|
|
is_default: false,
|
|
is_default: false,
|
|
generate_new_api_key: true,
|
|
generate_new_api_key: true,
|
|
@@ -1412,7 +1416,7 @@ export default {
|
|
role_description: "",
|
|
role_description: "",
|
|
role_permissions: "",
|
|
role_permissions: "",
|
|
custom_variables: "",
|
|
custom_variables: "",
|
|
- custom_prompt: "",
|
|
|
|
|
|
+ custom_prompt: "使用以下上下文来回答问题。如果你不知道答案,就说你不知道,不要试图编造答案。上下文: {context} 人类: {question}AI助手: 让我根据提供的上下文来回答你的问题。{custom_greeting}",
|
|
application_type: "",
|
|
application_type: "",
|
|
is_default: false,
|
|
is_default: false,
|
|
generate_new_api_key: true,
|
|
generate_new_api_key: true,
|
|
@@ -1462,9 +1466,10 @@ export default {
|
|
this.init();
|
|
this.init();
|
|
this.type = this.$route.query.type;
|
|
this.type = this.$route.query.type;
|
|
this.id = this.$route.query.id;
|
|
this.id = this.$route.query.id;
|
|
- if (this.type == "edit") {
|
|
|
|
- this.initEdit();
|
|
|
|
- } else if (this.type == "view") {
|
|
|
|
|
|
+ /* if (this.type == "edit") {
|
|
|
|
+ this.initEdit();
|
|
|
|
+
|
|
|
|
+ } else */ if (this.type == "view") {
|
|
this.initView();
|
|
this.initView();
|
|
}
|
|
}
|
|
},
|
|
},
|
|
@@ -1472,16 +1477,39 @@ export default {
|
|
/*组件方法*/
|
|
/*组件方法*/
|
|
methods: {
|
|
methods: {
|
|
/* 编辑 */
|
|
/* 编辑 */
|
|
|
|
+ handleEditDocumentChange(selectedValues) {
|
|
|
|
+ if (selectedValues.includes("all")) {
|
|
|
|
+ // 如果选择了"全部",则清空其他选项
|
|
|
|
+ this.editForm.documents = ["all"];
|
|
|
|
+ } else {
|
|
|
|
+ // 如果没有选择"全部",则限制最多选择10个文档
|
|
|
|
+ if (selectedValues.length > 10) {
|
|
|
|
+ this.editForm.documents = selectedValues.slice(0, 10);
|
|
|
|
+ this.$message.warning("最多只能选择10个文档");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ },
|
|
/* 编辑确认修改 */
|
|
/* 编辑确认修改 */
|
|
submitEdit() {
|
|
submitEdit() {
|
|
this.$refs.editFormRef.validate(async (valid) => {
|
|
this.$refs.editFormRef.validate(async (valid) => {
|
|
if (valid) {
|
|
if (valid) {
|
|
try {
|
|
try {
|
|
const convertedForm = { ...this.editForm };
|
|
const convertedForm = { ...this.editForm };
|
|
- console.log(this.editForm);
|
|
|
|
// 转换知识库、文档目录和文档的ID为名称
|
|
// 转换知识库、文档目录和文档的ID为名称
|
|
/* convertedForm.knowledge_base_names = this.safeGetNamesByIds(this.editForm.knowledge_base_names, this.kneList); */
|
|
/* convertedForm.knowledge_base_names = this.safeGetNamesByIds(this.editForm.knowledge_base_names, this.kneList); */
|
|
/* convertedForm.documents = this.safeGetNamesByIds(this.editForm.documents, this.editDocumentList); */
|
|
/* convertedForm.documents = this.safeGetNamesByIds(this.editForm.documents, this.editDocumentList); */
|
|
|
|
+ // 处理文档选择
|
|
|
|
+ if (
|
|
|
|
+ convertedForm.documents.includes("all") ||
|
|
|
|
+ convertedForm.documents.length === 0
|
|
|
|
+ ) {
|
|
|
|
+ convertedForm.documents = []; // 全选或未选择时传空数组给后台
|
|
|
|
+ } else {
|
|
|
|
+ convertedForm.documents = this.safeGetNamesByIds(
|
|
|
|
+ convertedForm.documents,
|
|
|
|
+ this.editDocumentList
|
|
|
|
+ );
|
|
|
|
+ }
|
|
convertedForm.document_directories = this.safeGetNamesByIds(
|
|
convertedForm.document_directories = this.safeGetNamesByIds(
|
|
this.editForm.document_directories,
|
|
this.editForm.document_directories,
|
|
this.editDirectoryList
|
|
this.editDirectoryList
|
|
@@ -1652,7 +1680,7 @@ export default {
|
|
role_description: "",
|
|
role_description: "",
|
|
role_permissions: "",
|
|
role_permissions: "",
|
|
custom_variables: "",
|
|
custom_variables: "",
|
|
- custom_prompt: "",
|
|
|
|
|
|
+ custom_prompt: "使用以下上下文来回答问题。如果你不知道答案,就说你不知道,不要试图编造答案。上下文: {context} 人类: {question}AI助手: 让我根据提供的上下文来回答你的问题。{custom_greeting}",
|
|
application_type: "",
|
|
application_type: "",
|
|
is_default: false,
|
|
is_default: false,
|
|
generate_new_api_key: true,
|
|
generate_new_api_key: true,
|
|
@@ -1676,6 +1704,18 @@ export default {
|
|
.catch((_) => {});
|
|
.catch((_) => {});
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
+ handleDocumentChange(selectedValues) {
|
|
|
|
+ if (selectedValues.includes("all")) {
|
|
|
|
+ // 如果选择了"全部",则清空其他选项
|
|
|
|
+ this.AIform.documents = ["all"];
|
|
|
|
+ } else {
|
|
|
|
+ // 如果没有选择"全部",则限制最多选择10个文档
|
|
|
|
+ if (selectedValues.length > 10) {
|
|
|
|
+ this.AIform.documents = selectedValues.slice(0, 10);
|
|
|
|
+ this.$message.warning("最多只能选择10个文档");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ },
|
|
/* 新增聊天应用 */
|
|
/* 新增聊天应用 */
|
|
generateApplication() {
|
|
generateApplication() {
|
|
this.$refs.AIformRef.validate(async (valid) => {
|
|
this.$refs.AIformRef.validate(async (valid) => {
|
|
@@ -1685,16 +1725,28 @@ export default {
|
|
const convertedForm = { ...this.AIform };
|
|
const convertedForm = { ...this.AIform };
|
|
|
|
|
|
// 将知识库 ID 转换为名称
|
|
// 将知识库 ID 转换为名称
|
|
- convertedForm.knowledge_base_names = this.safeGetNamesByIds(
|
|
|
|
|
|
+ /* convertedForm.knowledge_base_names = this.safeGetNamesByIds(
|
|
this.AIform.knowledge_base_names,
|
|
this.AIform.knowledge_base_names,
|
|
this.kneList
|
|
this.kneList
|
|
- );
|
|
|
|
|
|
+ ); */
|
|
|
|
|
|
- // 将文档 ID 转换为名称
|
|
|
|
|
|
+ /* // 将文档 ID 转换为名称
|
|
convertedForm.documents = this.safeGetNamesByIds(
|
|
convertedForm.documents = this.safeGetNamesByIds(
|
|
this.AIform.documents,
|
|
this.AIform.documents,
|
|
this.documentList
|
|
this.documentList
|
|
- );
|
|
|
|
|
|
+ ); */
|
|
|
|
+ // 处理文档选择
|
|
|
|
+ if (
|
|
|
|
+ convertedForm.documents.includes("all") ||
|
|
|
|
+ convertedForm.documents.length === 0
|
|
|
|
+ ) {
|
|
|
|
+ convertedForm.documents = []; // 全选或未选择时传空数组给后台
|
|
|
|
+ } else {
|
|
|
|
+ convertedForm.documents = this.safeGetNamesByIds(
|
|
|
|
+ convertedForm.documents,
|
|
|
|
+ this.documentList
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
|
|
// 将文档目录 ID 转换为名称,如果为空则传递 '全部'
|
|
// 将文档目录 ID 转换为名称,如果为空则传递 '全部'
|
|
convertedForm.document_directories = this.safeGetNamesByIds(
|
|
convertedForm.document_directories = this.safeGetNamesByIds(
|
|
@@ -1851,6 +1903,9 @@ export default {
|
|
/* 知识库 */
|
|
/* 知识库 */
|
|
listBuckets({ user_id: this.$store.state.user.id }).then((res) => {
|
|
listBuckets({ user_id: this.$store.state.user.id }).then((res) => {
|
|
this.kneList = res.data;
|
|
this.kneList = res.data;
|
|
|
|
+ if (this.$route.query.type == "edit") {
|
|
|
|
+ this.initEdit();
|
|
|
|
+ }
|
|
});
|
|
});
|
|
/* 应用列表 */
|
|
/* 应用列表 */
|
|
configList().then((res) => {
|
|
configList().then((res) => {
|
|
@@ -1869,12 +1924,12 @@ export default {
|
|
this.editForm = JSON.parse(JSON.stringify(this.$route.query.card)); // 深拷贝以避免直接修改原对象
|
|
this.editForm = JSON.parse(JSON.stringify(this.$route.query.card)); // 深拷贝以避免直接修改原对象
|
|
|
|
|
|
// 处理 knowledge_base_names
|
|
// 处理 knowledge_base_names
|
|
- this.editForm.knowledge_base_names =
|
|
|
|
|
|
+ /* this.editForm.knowledge_base_names =
|
|
this.editForm.knowledge_base_names.map((name) => {
|
|
this.editForm.knowledge_base_names.map((name) => {
|
|
- const kb = this.kneList.find((kb) => kb.name === name);
|
|
|
|
|
|
+ const kb = this.kneList.find((kb) => kb.name == name);
|
|
|
|
+ console.log(this.kneList);
|
|
return kb ? kb.id : name; // 如果找不到对应的知识库,保留原名称
|
|
return kb ? kb.id : name; // 如果找不到对应的知识库,保留原名称
|
|
- });
|
|
|
|
-
|
|
|
|
|
|
+ }); */
|
|
// 处理 role_permissions
|
|
// 处理 role_permissions
|
|
if (this.editForm.role_permissions) {
|
|
if (this.editForm.role_permissions) {
|
|
if (typeof this.editForm.role_permissions !== "string") {
|
|
if (typeof this.editForm.role_permissions !== "string") {
|
|
@@ -1901,7 +1956,34 @@ export default {
|
|
}
|
|
}
|
|
|
|
|
|
// 加载知识库对应的目录列表
|
|
// 加载知识库对应的目录列表
|
|
- this.loadEditDirectoryList(this.editForm.knowledge_base_names);
|
|
|
|
|
|
+ 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]); */
|
|
/* this.loadEditDocumentList(this.editForm.document_directories[0]); */
|
|
},
|
|
},
|
|
/* 查看 */
|
|
/* 查看 */
|
|
@@ -1941,6 +2023,16 @@ export default {
|
|
this.viewForm.custom_variables = "";
|
|
this.viewForm.custom_variables = "";
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /* // 处理文档选择
|
|
|
|
+ if (this.editForm.documents.length === 0 || this.editForm.documents.includes('全部')) {
|
|
|
|
+ this.editForm.documents = ['all'];
|
|
|
|
+ } else {
|
|
|
|
+ // 将文档名称转换为ID
|
|
|
|
+ this.editForm.documents = this.editForm.documents.map(docName => {
|
|
|
|
+ const doc = this.editDocumentList.find(d => d.name === docName);
|
|
|
|
+ return doc ? doc.id : docName;
|
|
|
|
+ });
|
|
|
|
+ } */
|
|
// 加载知识库对应的目录列表
|
|
// 加载知识库对应的目录列表
|
|
this.loadEditDirectoryList(this.viewForm.knowledge_base_names);
|
|
this.loadEditDirectoryList(this.viewForm.knowledge_base_names);
|
|
},
|
|
},
|