UnisKB/ui/src/views/dataset/step/StepSecond.vue

257 lines
7.6 KiB
Vue
Raw Normal View History

2023-11-02 01:56:14 +00:00
<template>
<div class="set-rules">
2023-11-21 07:22:10 +00:00
<el-row>
2023-11-17 03:36:16 +00:00
<el-col :span="10" class="p-24">
2023-12-05 11:21:13 +00:00
<h4 class="title-decoration-1 mb-16">设置分段规则</h4>
2023-11-22 09:04:47 +00:00
<div class="set-rules__right">
2023-11-06 11:06:02 +00:00
<el-scrollbar>
2023-12-05 11:21:13 +00:00
<div class="left-height" @click.stop>
2023-11-06 11:06:02 +00:00
<el-radio-group v-model="radio" class="set-rules__radio">
2023-12-05 11:21:13 +00:00
<el-card shadow="never" class="mb-16" :class="radio === '1' ? 'active' : ''">
<el-radio value="1" size="large">
2023-12-05 11:21:13 +00:00
<p class="mb-4">智能分段推荐)</p>
<el-text type="info">不了解如何设置分段规则推荐使用智能分段</el-text>
</el-radio>
</el-card>
<el-card shadow="never" class="mb-16" :class="radio === '2' ? 'active' : ''">
<el-radio value="2" size="large">
2023-12-05 11:21:13 +00:00
<p class="mb-4">高级分段</p>
<el-text type="info"
>用户可根据文档规范自行设置分段标识符分段长度以及清洗规则
</el-text>
</el-radio>
<el-card
v-if="radio === '2'"
shadow="never"
class="card-never mt-16"
style="margin-left: 30px"
>
2023-11-08 11:08:54 +00:00
<div class="set-rules__form">
<div class="form-item mb-16">
<div class="title flex align-center mb-8">
<span style="margin-right: 4px">分段标识</span>
2023-11-21 02:56:25 +00:00
<el-tooltip
effect="dark"
content="按照所选符号先后顺序做递归分割,分割结果超出分段长度将截取至分段长度。"
placement="right"
>
2024-02-26 07:34:21 +00:00
<AppIcon iconName="app-warning" class="app-warning-icon"></AppIcon>
2023-11-14 10:12:55 +00:00
</el-tooltip>
2023-11-08 11:08:54 +00:00
</div>
2023-12-05 11:21:13 +00:00
<div @click.stop>
2024-01-11 07:01:31 +00:00
<el-select
v-model="form.patterns"
multiple
allow-create
default-first-option
filterable
placeholder="请选择"
>
2023-12-05 11:21:13 +00:00
<el-option
v-for="(item, index) in splitPatternList"
:key="index"
:label="item.key"
:value="item.value"
>
</el-option>
</el-select>
</div>
2023-11-08 11:08:54 +00:00
</div>
<div class="form-item mb-16">
<div class="title mb-8">分段长度</div>
2023-11-21 02:56:25 +00:00
<el-slider
v-model="form.limit"
show-input
:show-input-controls="false"
:min="50"
2024-01-02 09:32:41 +00:00
:max="4096"
2023-11-21 02:56:25 +00:00
/>
2023-11-08 11:08:54 +00:00
</div>
<div class="form-item mb-16">
<div class="title mb-8">自动清洗</div>
2023-12-05 11:21:13 +00:00
<el-switch size="small" v-model="form.with_filter" />
2023-11-08 11:08:54 +00:00
<div style="margin-top: 4px">
<el-text type="info">去掉重复多余符号空格空行制表符</el-text>
</div>
</div>
</div>
2023-11-06 11:06:02 +00:00
</el-card>
2023-12-05 11:21:13 +00:00
</el-card>
2023-11-06 11:06:02 +00:00
</el-radio-group>
</div>
</el-scrollbar>
<div>
<el-checkbox v-model="checkedConnect" @change="changeHandle">
导入时添加分段标题为关联问题适用于标题为问题的问答对
</el-checkbox>
</div>
<div class="text-right mt-8">
2023-11-06 11:06:02 +00:00
<el-button @click="splitDocument"></el-button>
2023-11-02 01:56:14 +00:00
</div>
</div>
</el-col>
2023-11-17 03:36:16 +00:00
<el-col :span="14" class="p-24 border-l">
2023-11-10 09:18:00 +00:00
<div v-loading="loading">
2023-11-06 11:06:02 +00:00
<h4 class="title-decoration-1 mb-8">分段预览</h4>
2024-05-09 09:46:57 +00:00
<ParagraphPreview v-model:data="paragraphList" :isConnect="checkedConnect" />
2023-11-06 11:06:02 +00:00
</div>
2023-11-02 01:56:14 +00:00
</el-col>
</el-row>
</div>
</template>
<script setup lang="ts">
2023-11-21 02:57:20 +00:00
import { ref, computed, onMounted, reactive, watch } from 'vue'
2023-11-14 10:12:55 +00:00
import ParagraphPreview from '@/views/dataset/component/ParagraphPreview.vue'
2023-11-22 10:37:08 +00:00
import documentApi from '@/api/document'
2023-11-02 01:56:14 +00:00
import useStore from '@/stores'
import type { KeyValue } from '@/api/type/common'
2023-11-02 01:56:14 +00:00
const { dataset } = useStore()
const documentsFiles = computed(() => dataset.documentsFiles)
2023-11-21 02:57:20 +00:00
const splitPatternList = ref<Array<KeyValue<string, string>>>([])
2023-11-02 01:56:14 +00:00
2023-11-06 11:06:02 +00:00
const radio = ref('1')
2023-11-02 01:56:14 +00:00
const loading = ref(false)
2023-11-14 10:12:55 +00:00
const paragraphList = ref<any[]>([])
2023-11-21 02:57:20 +00:00
const patternLoading = ref<boolean>(false)
const checkedConnect = ref<boolean>(false)
const firstChecked = ref(true)
2023-11-06 11:06:02 +00:00
const form = reactive<{
2023-11-22 09:04:47 +00:00
patterns: Array<string>
limit: number
with_filter: boolean
[propName: string]: any
}>({
patterns: [],
2023-12-05 11:21:13 +00:00
limit: 500,
with_filter: true
2023-11-06 11:06:02 +00:00
})
function changeHandle(val: boolean) {
if (val && firstChecked.value) {
const list = paragraphList.value
list.map((item: any) => {
item.content.map((v: any) => {
v['problem_list'] = v.title
? [
{
content: v.title
}
]
: []
})
})
paragraphList.value = list
firstChecked.value = false
}
}
2023-11-02 01:56:14 +00:00
function splitDocument() {
loading.value = true
let fd = new FormData()
documentsFiles.value.forEach((item) => {
if (item?.raw) {
fd.append('file', item?.raw)
}
})
2023-11-10 09:18:00 +00:00
if (radio.value === '2') {
Object.keys(form).forEach((key) => {
if (key == 'patterns') {
2023-11-22 09:04:47 +00:00
form.patterns.forEach((item) => fd.append('patterns', item))
} else {
fd.append(key, form[key])
}
2023-11-10 09:18:00 +00:00
})
}
2023-12-05 11:21:13 +00:00
documentApi
.postSplitDocument(fd)
2023-11-06 11:06:02 +00:00
.then((res: any) => {
const list = res.data
if (checkedConnect.value) {
list.map((item: any) => {
item.content.map((v: any) => {
v['problem_list'] = v.title
? [
{
content: v.title
}
]
: []
})
})
}
2023-11-14 10:12:55 +00:00
paragraphList.value = res.data
2023-11-02 01:56:14 +00:00
loading.value = false
})
.catch(() => {
loading.value = false
})
}
const initSplitPatternList = () => {
2023-11-22 10:37:08 +00:00
documentApi.listSplitPattern(patternLoading).then((ok) => {
2023-11-21 02:57:20 +00:00
splitPatternList.value = ok.data
})
}
2023-11-21 02:57:20 +00:00
watch(radio, () => {
if (radio.value === '2') {
initSplitPatternList()
}
})
2023-11-10 09:18:00 +00:00
onMounted(() => {
splitDocument()
})
defineExpose({
paragraphList,
checkedConnect
2023-11-10 09:18:00 +00:00
})
2023-11-02 01:56:14 +00:00
</script>
<style scoped lang="scss">
.set-rules {
2023-11-06 11:06:02 +00:00
width: 100%;
2023-11-21 02:57:20 +00:00
2023-11-08 11:08:54 +00:00
.left-height {
2023-11-21 07:22:10 +00:00
max-height: calc(var(--create-dataset-height) - 70px);
2023-11-08 11:08:54 +00:00
overflow-x: hidden;
}
2023-11-21 02:57:20 +00:00
2023-11-02 01:56:14 +00:00
&__radio {
2023-12-05 11:21:13 +00:00
width: 100%;
2023-11-02 01:56:14 +00:00
display: block;
2023-11-21 02:57:20 +00:00
2023-11-06 11:06:02 +00:00
.el-radio {
white-space: break-spaces;
width: 100%;
height: 100%;
line-height: 22px;
2023-11-13 11:02:13 +00:00
color: var(--app-text-color);
2023-11-06 11:06:02 +00:00
}
2023-11-21 02:57:20 +00:00
2023-11-06 11:06:02 +00:00
:deep(.el-radio__label) {
2023-12-05 11:21:13 +00:00
padding-left: 30px;
2023-11-08 11:08:54 +00:00
width: 100%;
2023-11-06 11:06:02 +00:00
}
:deep(.el-radio__input) {
position: absolute;
2023-12-05 11:21:13 +00:00
top: 16px;
}
.active {
border: 1px solid var(--el-color-primary);
2023-11-06 11:06:02 +00:00
}
}
2023-11-21 02:57:20 +00:00
2023-11-08 11:08:54 +00:00
&__form {
.title {
font-size: 14px;
font-weight: 400;
}
2023-11-02 01:56:14 +00:00
}
}
</style>