216 lines
7.6 KiB
Vue
216 lines
7.6 KiB
Vue
|
|
<template>
|
||
|
|
<NodeContainer :nodeModel="nodeModel">
|
||
|
|
<h5 class="title-decoration-1 mb-8">{{ $t('views.applicationWorkflow.nodeSetting') }}</h5>
|
||
|
|
<el-card shadow="never" class="card-never">
|
||
|
|
<el-form
|
||
|
|
@submit.prevent
|
||
|
|
:model="form_data"
|
||
|
|
label-position="top"
|
||
|
|
require-asterisk-position="right"
|
||
|
|
label-width="auto"
|
||
|
|
ref="DatasetNodeFormRef"
|
||
|
|
>
|
||
|
|
<el-form-item :label="$t('views.chatLog.selectKnowledge')">
|
||
|
|
<template #label>
|
||
|
|
<div class="flex-between">
|
||
|
|
<span>{{ $t('views.chatLog.selectKnowledge') }}</span>
|
||
|
|
<el-button type="primary" link @click="openDatasetDialog">
|
||
|
|
<el-icon><Plus /></el-icon>
|
||
|
|
</el-button>
|
||
|
|
</div>
|
||
|
|
</template>
|
||
|
|
<div class="w-full">
|
||
|
|
<el-text type="info" v-if="form_data.dataset_id_list?.length === 0">
|
||
|
|
{{ $t('views.application.form.relatedKnowledge.placeholder') }}
|
||
|
|
</el-text>
|
||
|
|
<template v-for="(item, index) in form_data.dataset_id_list" :key="index" v-else>
|
||
|
|
<div class="flex-between border border-r-4 white-bg mb-4" style="padding: 5px 8px">
|
||
|
|
<div class="flex align-center" style="line-height: 20px">
|
||
|
|
<KnowledgeIcon :type="relatedObject(datasetList, item, 'id')?.type" />
|
||
|
|
|
||
|
|
<div class="ellipsis" :title="relatedObject(datasetList, item, 'id')?.name">
|
||
|
|
{{ relatedObject(datasetList, item, 'id')?.name }}
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<el-button text @click="removeDataset(item)">
|
||
|
|
<el-icon><Close /></el-icon>
|
||
|
|
</el-button>
|
||
|
|
</div>
|
||
|
|
</template>
|
||
|
|
</div>
|
||
|
|
</el-form-item>
|
||
|
|
<el-form-item :label="$t('views.applicationWorkflow.nodes.searchDatasetNode.searchParam')">
|
||
|
|
<template #label>
|
||
|
|
<div class="flex-between">
|
||
|
|
<span>{{ $t('views.applicationWorkflow.nodes.searchDatasetNode.searchParam') }}</span>
|
||
|
|
<el-button type="primary" link @click="openParamSettingDialog">
|
||
|
|
<el-icon><Setting /></el-icon>
|
||
|
|
</el-button>
|
||
|
|
</div>
|
||
|
|
</template>
|
||
|
|
<div class="w-full">
|
||
|
|
<el-row>
|
||
|
|
<el-col :span="12" class="color-secondary lighter">{{
|
||
|
|
$t('views.application.dialog.selectSearchMode')
|
||
|
|
}}</el-col>
|
||
|
|
<el-col :span="12" class="lighter">
|
||
|
|
{{
|
||
|
|
$t(SearchMode[form_data.dataset_setting.search_mode as keyof typeof SearchMode])
|
||
|
|
}}</el-col
|
||
|
|
>
|
||
|
|
<el-col :span="12" class="color-secondary lighter">
|
||
|
|
{{ $t('views.application.dialog.similarityThreshold') }}</el-col
|
||
|
|
>
|
||
|
|
<el-col :span="12" class="lighter">
|
||
|
|
{{ form_data.dataset_setting.similarity?.toFixed(3) }}</el-col
|
||
|
|
>
|
||
|
|
<el-col :span="12" class="color-secondary lighter">{{
|
||
|
|
$t('views.application.dialog.topReferences')
|
||
|
|
}}</el-col>
|
||
|
|
<el-col :span="12" class="lighter"> {{ form_data.dataset_setting.top_n }}</el-col>
|
||
|
|
<el-col :span="12" class="color-secondary lighter">
|
||
|
|
{{ $t('views.application.dialog.maxCharacters') }}</el-col
|
||
|
|
>
|
||
|
|
<el-col :span="12" class="lighter">
|
||
|
|
{{ form_data.dataset_setting.max_paragraph_char_number }}</el-col
|
||
|
|
>
|
||
|
|
</el-row>
|
||
|
|
</div>
|
||
|
|
</el-form-item>
|
||
|
|
<el-form-item
|
||
|
|
:label="$t('views.applicationWorkflow.nodes.searchDatasetNode.searchQuestion.label')"
|
||
|
|
prop="question_reference_address"
|
||
|
|
:rules="{
|
||
|
|
message: $t(
|
||
|
|
'views.applicationWorkflow.nodes.searchDatasetNode.searchQuestion.requiredMessage',
|
||
|
|
),
|
||
|
|
trigger: 'blur',
|
||
|
|
required: true,
|
||
|
|
}"
|
||
|
|
>
|
||
|
|
<NodeCascader
|
||
|
|
ref="nodeCascaderRef"
|
||
|
|
:nodeModel="nodeModel"
|
||
|
|
class="w-full"
|
||
|
|
:placeholder="
|
||
|
|
$t('views.applicationWorkflow.nodes.searchDatasetNode.searchQuestion.placeholder')
|
||
|
|
"
|
||
|
|
v-model="form_data.question_reference_address"
|
||
|
|
/>
|
||
|
|
</el-form-item>
|
||
|
|
</el-form>
|
||
|
|
</el-card>
|
||
|
|
<ParamSettingDialog ref="ParamSettingDialogRef" @refresh="refreshParam" />
|
||
|
|
<AddDatasetDialog
|
||
|
|
ref="AddDatasetDialogRef"
|
||
|
|
@addData="addKnowledge"
|
||
|
|
:data="datasetList"
|
||
|
|
@refresh="refresh"
|
||
|
|
:loading="datasetLoading"
|
||
|
|
/>
|
||
|
|
</NodeContainer>
|
||
|
|
</template>
|
||
|
|
<script setup lang="ts">
|
||
|
|
import { set } from 'lodash'
|
||
|
|
import { app } from '@/main'
|
||
|
|
import NodeContainer from '@/workflow/common/NodeContainer.vue'
|
||
|
|
import NodeCascader from '@/workflow/common/NodeCascader.vue'
|
||
|
|
import AddDatasetDialog from '@/views/application/component/AddKnowledgeDialog.vue'
|
||
|
|
import ParamSettingDialog from '@/views/application/component/ParamSettingDialog.vue'
|
||
|
|
import type { FormInstance } from 'element-plus'
|
||
|
|
import { ref, computed, onMounted } from 'vue'
|
||
|
|
import { relatedObject } from '@/utils/utils'
|
||
|
|
import { SearchMode } from '@/enums/application'
|
||
|
|
import useStore from '@/stores'
|
||
|
|
const { knowledge, application, user } = useStore()
|
||
|
|
const {
|
||
|
|
params: { id },
|
||
|
|
} = app.config.globalProperties.$route as any
|
||
|
|
|
||
|
|
const props = defineProps<{ nodeModel: any }>()
|
||
|
|
const nodeCascaderRef = ref()
|
||
|
|
const form = {
|
||
|
|
dataset_id_list: [],
|
||
|
|
dataset_setting: {
|
||
|
|
top_n: 3,
|
||
|
|
similarity: 0.6,
|
||
|
|
max_paragraph_char_number: 5000,
|
||
|
|
search_mode: 'embedding',
|
||
|
|
},
|
||
|
|
question_reference_address: [],
|
||
|
|
}
|
||
|
|
|
||
|
|
const form_data = computed({
|
||
|
|
get: () => {
|
||
|
|
if (props.nodeModel.properties.node_data) {
|
||
|
|
return props.nodeModel.properties.node_data
|
||
|
|
} else {
|
||
|
|
set(props.nodeModel.properties, 'node_data', form)
|
||
|
|
}
|
||
|
|
return props.nodeModel.properties.node_data
|
||
|
|
},
|
||
|
|
set: (value) => {
|
||
|
|
set(props.nodeModel.properties, 'node_data', value)
|
||
|
|
},
|
||
|
|
})
|
||
|
|
|
||
|
|
const DatasetNodeFormRef = ref<FormInstance>()
|
||
|
|
const ParamSettingDialogRef = ref<InstanceType<typeof ParamSettingDialog>>()
|
||
|
|
const AddDatasetDialogRef = ref<InstanceType<typeof AddDatasetDialog>>()
|
||
|
|
const datasetList = ref<any>([])
|
||
|
|
const datasetLoading = ref(false)
|
||
|
|
|
||
|
|
function refreshParam(data: any) {
|
||
|
|
set(props.nodeModel.properties.node_data, 'dataset_setting', data.dataset_setting)
|
||
|
|
}
|
||
|
|
|
||
|
|
const openParamSettingDialog = () => {
|
||
|
|
ParamSettingDialogRef.value?.open(form_data.value, 'WORK_FLOW')
|
||
|
|
}
|
||
|
|
|
||
|
|
function removeDataset(id: any) {
|
||
|
|
const list = props.nodeModel.properties.node_data.dataset_id_list.filter((v: any) => v !== id)
|
||
|
|
set(props.nodeModel.properties.node_data, 'dataset_id_list', list)
|
||
|
|
}
|
||
|
|
|
||
|
|
function addKnowledge(val: Array<string>) {
|
||
|
|
set(props.nodeModel.properties.node_data, 'dataset_id_list', val)
|
||
|
|
}
|
||
|
|
|
||
|
|
function openDatasetDialog() {
|
||
|
|
if (AddDatasetDialogRef.value) {
|
||
|
|
AddDatasetDialogRef.value.open(form_data.value.dataset_id_list)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
function getDataset() {
|
||
|
|
// if (id) {
|
||
|
|
// application.asyncGetApplicationKnowledge(id, datasetLoading).then((res: any) => {
|
||
|
|
// datasetList.value = res.data
|
||
|
|
// })
|
||
|
|
// } else {
|
||
|
|
knowledge.asyncGetRootKnowledge(datasetLoading).then((res: any) => {
|
||
|
|
datasetList.value = res.data?.filter((v: any) => v.user_id === user.userInfo?.id)
|
||
|
|
})
|
||
|
|
// }
|
||
|
|
}
|
||
|
|
function refresh() {
|
||
|
|
getDataset()
|
||
|
|
}
|
||
|
|
|
||
|
|
const validate = () => {
|
||
|
|
return Promise.all([
|
||
|
|
nodeCascaderRef.value.validate(),
|
||
|
|
DatasetNodeFormRef.value?.validate(),
|
||
|
|
]).catch((err) => {
|
||
|
|
return Promise.reject({ node: props.nodeModel, errMessage: err })
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
onMounted(() => {
|
||
|
|
getDataset()
|
||
|
|
set(props.nodeModel, 'validate', validate)
|
||
|
|
})
|
||
|
|
</script>
|
||
|
|
<style lang="scss" scoped></style>
|