2024-01-11 06:40:00 +00:00
|
|
|
|
<template>
|
|
|
|
|
|
<el-dialog
|
2024-01-19 08:03:17 +00:00
|
|
|
|
title="导入文档"
|
2024-01-11 06:40:00 +00:00
|
|
|
|
v-model="dialogVisible"
|
|
|
|
|
|
:close-on-click-modal="false"
|
|
|
|
|
|
:close-on-press-escape="false"
|
|
|
|
|
|
:destroy-on-close="true"
|
|
|
|
|
|
>
|
2024-01-19 08:03:17 +00:00
|
|
|
|
<el-form
|
|
|
|
|
|
label-position="top"
|
|
|
|
|
|
ref="webFormRef"
|
|
|
|
|
|
:rules="rules"
|
|
|
|
|
|
:model="form"
|
|
|
|
|
|
require-asterisk-position="right"
|
|
|
|
|
|
>
|
|
|
|
|
|
<el-form-item label="文档地址" prop="source_url" v-if="isImport">
|
|
|
|
|
|
<el-input
|
|
|
|
|
|
v-model="form.source_url"
|
|
|
|
|
|
placeholder="请输入文档地址,一行一个,地址不正确文档会导入失败。"
|
|
|
|
|
|
:rows="10"
|
|
|
|
|
|
type="textarea"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</el-form-item>
|
2024-04-25 02:44:14 +00:00
|
|
|
|
<el-form-item v-else-if="documentType === '1'" label="文档地址" prop="source_url">
|
2024-01-19 08:03:17 +00:00
|
|
|
|
<el-input v-model="form.source_url" placeholder="请输入文档地址" />
|
|
|
|
|
|
</el-form-item>
|
2024-04-25 02:44:14 +00:00
|
|
|
|
<el-form-item label="选择器" v-if="documentType === '1'">
|
2024-01-19 08:03:17 +00:00
|
|
|
|
<el-input
|
|
|
|
|
|
v-model="form.selector"
|
|
|
|
|
|
placeholder="默认为 body,可输入 .classname/#idname/tagname"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</el-form-item>
|
2024-04-25 02:44:14 +00:00
|
|
|
|
<el-form-item v-if="!isImport">
|
|
|
|
|
|
<template #label>
|
|
|
|
|
|
<div class="flex align-center">
|
|
|
|
|
|
<span class="mr-4">命中处理方式</span>
|
|
|
|
|
|
<el-tooltip
|
|
|
|
|
|
effect="dark"
|
|
|
|
|
|
content="用户提问时,命中文档下的分段时按照设置的方式进行处理。"
|
|
|
|
|
|
placement="right"
|
|
|
|
|
|
>
|
|
|
|
|
|
<AppIcon iconName="app-warning" class="app-warning-icon"></AppIcon>
|
|
|
|
|
|
</el-tooltip>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
2024-05-08 09:31:56 +00:00
|
|
|
|
<el-radio-group v-model="form.hit_handling_method" class="radio-block mt-4">
|
2024-04-25 02:44:14 +00:00
|
|
|
|
<template v-for="(value, key) of hitHandlingMethod" :key="key">
|
2024-05-08 09:31:56 +00:00
|
|
|
|
<el-radio :value="key">{{ value }} </el-radio>
|
2024-04-25 02:44:14 +00:00
|
|
|
|
</template>
|
|
|
|
|
|
</el-radio-group>
|
2024-05-08 09:31:56 +00:00
|
|
|
|
<div
|
|
|
|
|
|
v-if="form.hit_handling_method === 'directly_return'"
|
|
|
|
|
|
class="lighter"
|
|
|
|
|
|
style="margin-left: 21px"
|
|
|
|
|
|
>
|
|
|
|
|
|
<span>相似度高于</span>
|
|
|
|
|
|
<el-input-number
|
|
|
|
|
|
v-model="form.directly_return_similarity"
|
|
|
|
|
|
:min="0"
|
|
|
|
|
|
:max="1"
|
|
|
|
|
|
:precision="3"
|
|
|
|
|
|
:step="0.1"
|
|
|
|
|
|
controls-position="right"
|
|
|
|
|
|
size="small"
|
|
|
|
|
|
class="ml-4 mr-4"
|
|
|
|
|
|
/><span>直接返回分段内容</span>
|
|
|
|
|
|
</div>
|
2024-04-25 02:44:14 +00:00
|
|
|
|
</el-form-item>
|
2024-01-19 08:03:17 +00:00
|
|
|
|
</el-form>
|
2024-01-11 06:40:00 +00:00
|
|
|
|
<template #footer>
|
|
|
|
|
|
<span class="dialog-footer">
|
|
|
|
|
|
<el-button @click.prevent="dialogVisible = false"> 取消 </el-button>
|
2024-03-04 06:16:25 +00:00
|
|
|
|
<el-button type="primary" @click="submit(webFormRef)" :loading="loading"> 确定 </el-button>
|
2024-01-11 06:40:00 +00:00
|
|
|
|
</span>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-dialog>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts">
|
2024-01-19 08:03:17 +00:00
|
|
|
|
import { ref, reactive, watch } from 'vue'
|
|
|
|
|
|
import { useRoute } from 'vue-router'
|
2024-03-04 06:16:25 +00:00
|
|
|
|
import type { FormInstance, FormRules } from 'element-plus'
|
2024-01-19 08:03:17 +00:00
|
|
|
|
import documentApi from '@/api/document'
|
2024-01-11 06:40:00 +00:00
|
|
|
|
import { MsgSuccess } from '@/utils/message'
|
2024-04-25 02:44:14 +00:00
|
|
|
|
import { hitHandlingMethod } from '../utils'
|
2024-01-11 06:40:00 +00:00
|
|
|
|
|
2024-01-19 08:03:17 +00:00
|
|
|
|
const route = useRoute()
|
|
|
|
|
|
const {
|
|
|
|
|
|
params: { id }
|
|
|
|
|
|
} = route as any
|
2024-01-11 06:40:00 +00:00
|
|
|
|
|
|
|
|
|
|
const emit = defineEmits(['refresh'])
|
2024-03-04 06:16:25 +00:00
|
|
|
|
const webFormRef = ref()
|
2024-01-11 06:40:00 +00:00
|
|
|
|
const loading = ref<boolean>(false)
|
2024-01-19 08:03:17 +00:00
|
|
|
|
const isImport = ref<boolean>(false)
|
|
|
|
|
|
const form = ref<any>({
|
|
|
|
|
|
source_url: '',
|
2024-04-25 02:44:14 +00:00
|
|
|
|
selector: '',
|
2024-05-08 09:31:56 +00:00
|
|
|
|
hit_handling_method: 'optimization',
|
|
|
|
|
|
directly_return_similarity: 0.9
|
2024-01-19 08:03:17 +00:00
|
|
|
|
})
|
2024-05-08 09:31:56 +00:00
|
|
|
|
|
|
|
|
|
|
// 文档设置
|
2024-01-19 09:51:27 +00:00
|
|
|
|
const documentId = ref('')
|
2024-04-25 02:44:14 +00:00
|
|
|
|
const documentType = ref<string | number>('') //文档类型:1: web文档;0:普通文档
|
2024-01-19 08:03:17 +00:00
|
|
|
|
|
2024-05-08 09:31:56 +00:00
|
|
|
|
// 批量设置
|
|
|
|
|
|
const documentList = ref<Array<string>>([])
|
|
|
|
|
|
|
2024-01-19 08:03:17 +00:00
|
|
|
|
const rules = reactive({
|
2024-01-24 02:38:48 +00:00
|
|
|
|
source_url: [{ required: true, message: '请输入文档地址', trigger: 'blur' }]
|
2024-01-19 08:03:17 +00:00
|
|
|
|
})
|
2024-01-11 06:40:00 +00:00
|
|
|
|
|
|
|
|
|
|
const dialogVisible = ref<boolean>(false)
|
|
|
|
|
|
|
|
|
|
|
|
watch(dialogVisible, (bool) => {
|
|
|
|
|
|
if (!bool) {
|
2024-01-19 08:03:17 +00:00
|
|
|
|
form.value = {
|
|
|
|
|
|
source_url: '',
|
2024-04-25 02:44:14 +00:00
|
|
|
|
selector: '',
|
2024-05-08 09:31:56 +00:00
|
|
|
|
hit_handling_method: 'optimization',
|
|
|
|
|
|
directly_return_similarity: 0.9
|
2024-01-19 08:03:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
isImport.value = false
|
2024-04-25 02:44:14 +00:00
|
|
|
|
documentType.value = ''
|
2024-05-08 09:31:56 +00:00
|
|
|
|
documentList.value = []
|
2024-01-11 06:40:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
|
2024-05-08 09:31:56 +00:00
|
|
|
|
const open = (row: any, list: Array<string>) => {
|
2024-01-19 08:03:17 +00:00
|
|
|
|
if (row) {
|
2024-04-25 02:44:14 +00:00
|
|
|
|
documentType.value = row.type
|
2024-01-19 09:51:27 +00:00
|
|
|
|
documentId.value = row.id
|
2024-05-08 09:31:56 +00:00
|
|
|
|
form.value = {
|
|
|
|
|
|
hit_handling_method: row.hit_handling_method,
|
|
|
|
|
|
directly_return_similarity: row.directly_return_similarity,
|
|
|
|
|
|
...row.meta
|
|
|
|
|
|
}
|
2024-01-19 08:03:17 +00:00
|
|
|
|
isImport.value = false
|
2024-05-08 09:31:56 +00:00
|
|
|
|
} else if (list) {
|
|
|
|
|
|
// 批量设置
|
|
|
|
|
|
documentList.value = list
|
2024-01-19 08:03:17 +00:00
|
|
|
|
} else {
|
2024-05-08 09:31:56 +00:00
|
|
|
|
// 导入
|
2024-01-19 08:03:17 +00:00
|
|
|
|
isImport.value = true
|
|
|
|
|
|
}
|
2024-01-11 06:40:00 +00:00
|
|
|
|
dialogVisible.value = true
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-04 06:16:25 +00:00
|
|
|
|
const submit = async (formEl: FormInstance | undefined) => {
|
|
|
|
|
|
if (!formEl) return
|
|
|
|
|
|
await formEl.validate((valid, fields) => {
|
|
|
|
|
|
if (valid) {
|
|
|
|
|
|
if (isImport.value) {
|
|
|
|
|
|
const obj = {
|
|
|
|
|
|
source_url_list: form.value.source_url.split('\n'),
|
|
|
|
|
|
selector: form.value.selector
|
|
|
|
|
|
}
|
|
|
|
|
|
documentApi.postWebDocument(id, obj, loading).then((res: any) => {
|
|
|
|
|
|
MsgSuccess('导入成功')
|
|
|
|
|
|
emit('refresh')
|
|
|
|
|
|
dialogVisible.value = false
|
|
|
|
|
|
})
|
|
|
|
|
|
} else {
|
2024-05-08 09:31:56 +00:00
|
|
|
|
if (documentId.value) {
|
|
|
|
|
|
const obj = {
|
|
|
|
|
|
hit_handling_method: form.value.hit_handling_method,
|
|
|
|
|
|
directly_return_similarity: form.value.directly_return_similarity,
|
|
|
|
|
|
meta: {
|
|
|
|
|
|
source_url: form.value.source_url,
|
|
|
|
|
|
selector: form.value.selector
|
|
|
|
|
|
}
|
2024-04-25 02:44:14 +00:00
|
|
|
|
}
|
2024-05-08 09:31:56 +00:00
|
|
|
|
documentApi.putDocument(id, documentId.value, obj, loading).then((res) => {
|
|
|
|
|
|
MsgSuccess('设置成功')
|
|
|
|
|
|
emit('refresh')
|
|
|
|
|
|
dialogVisible.value = false
|
|
|
|
|
|
})
|
|
|
|
|
|
} else if (documentList.value.length > 0) {
|
|
|
|
|
|
// 批量设置
|
|
|
|
|
|
const obj = {
|
|
|
|
|
|
hit_handling_method: form.value.hit_handling_method,
|
|
|
|
|
|
directly_return_similarity: form.value.directly_return_similarity,
|
|
|
|
|
|
id_list: documentList.value
|
|
|
|
|
|
}
|
|
|
|
|
|
documentApi.batchEditHitHandling(id, obj, loading).then((res: any) => {
|
|
|
|
|
|
MsgSuccess('设置成功')
|
|
|
|
|
|
emit('refresh')
|
|
|
|
|
|
dialogVisible.value = false
|
|
|
|
|
|
})
|
2024-03-04 06:16:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-01-19 09:51:27 +00:00
|
|
|
|
}
|
2024-03-04 06:16:25 +00:00
|
|
|
|
})
|
2024-01-11 06:40:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
defineExpose({ open })
|
|
|
|
|
|
</script>
|
2024-01-19 08:03:17 +00:00
|
|
|
|
<style lang="scss" scoped></style>
|