Merge branch 'main' of github.com:maxkb-dev/maxkb
This commit is contained in:
commit
c2baf85878
@ -82,7 +82,7 @@ const postDateset: (data: datasetData, loading?: Ref<boolean>) => Promise<Result
|
||||
* {
|
||||
"name": "string",
|
||||
"desc": "string",
|
||||
"url": "string",
|
||||
"source_url": "string",
|
||||
"selector": "string",
|
||||
}
|
||||
*/
|
||||
@ -97,8 +97,11 @@ const postWebDateset: (data: any, loading?: Ref<boolean>) => Promise<Result<any>
|
||||
* 知识库详情
|
||||
* @param 参数 dataset_id
|
||||
*/
|
||||
const getDatesetDetail: (dataset_id: string) => Promise<Result<any>> = (dataset_id) => {
|
||||
return get(`${prefix}/${dataset_id}`)
|
||||
const getDatesetDetail: (dataset_id: string, loading?: Ref<boolean>) => Promise<Result<any>> = (
|
||||
dataset_id,
|
||||
loading
|
||||
) => {
|
||||
return get(`${prefix}/${dataset_id}`, undefined, loading)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -144,6 +147,19 @@ const getDatasetHitTest: (
|
||||
return get(`${prefix}/${dataset_id}/hit_test`, data, loading)
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步知识库
|
||||
* @param 参数 dataset_id
|
||||
* @query 参数 sync_type // 同步类型->replace:替换同步,complete:完整同步
|
||||
*/
|
||||
const getSyncWebDateset: (
|
||||
dataset_id: string,
|
||||
sync_type: string,
|
||||
loading?: Ref<boolean>
|
||||
) => Promise<Result<any>> = (dataset_id, sync_type, loading) => {
|
||||
return get(`${prefix}/${dataset_id}`, { sync_type }, loading)
|
||||
}
|
||||
|
||||
export default {
|
||||
getDateset,
|
||||
getAllDateset,
|
||||
@ -153,5 +169,6 @@ export default {
|
||||
putDateset,
|
||||
listUsableApplication,
|
||||
getDatasetHitTest,
|
||||
postWebDateset
|
||||
postWebDateset,
|
||||
getSyncWebDateset
|
||||
}
|
||||
|
||||
@ -109,7 +109,16 @@ const delDocument: (dataset_id: string, document_id: string) => Promise<Result<b
|
||||
) => {
|
||||
return del(`${prefix}/${dataset_id}/document/${document_id}`)
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 批量删除文档
|
||||
// * @param 参数 dataset_id, document_id,
|
||||
// */
|
||||
// const delDocument: (dataset_id: string, document_id: string) => Promise<Result<boolean>> = (
|
||||
// dataset_id,
|
||||
// document_id
|
||||
// ) => {
|
||||
// return del(`${prefix}/${dataset_id}/document/${document_id}`)
|
||||
// }
|
||||
/**
|
||||
* 文档详情
|
||||
* @param 参数 dataset_id
|
||||
|
||||
@ -11,12 +11,32 @@
|
||||
|
||||
<div class="content">
|
||||
<el-card shadow="always" class="dialog-card">
|
||||
<template v-for="(item, index) in prologueList" :key="index">
|
||||
<div
|
||||
v-if="isMdArray(item)"
|
||||
@click="quickProblemHandel(item)"
|
||||
class="problem-button ellipsis-2 mb-8"
|
||||
:class="log ? 'disabled' : 'cursor'"
|
||||
>
|
||||
<el-icon><EditPen /></el-icon>
|
||||
{{ item }}
|
||||
</div>
|
||||
<MdPreview
|
||||
v-else
|
||||
class="mb-8"
|
||||
ref="editorRef"
|
||||
editorId="preview-only"
|
||||
:modelValue="item"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<!-- {{ prologueList }}
|
||||
<h4>您好,我是 {{ data?.name || '应用名称' }}</h4>
|
||||
<div class="mt-4" v-if="data?.prologue">
|
||||
<el-text type="info">{{ data?.prologue }}</el-text>
|
||||
</div>
|
||||
</div> -->
|
||||
</el-card>
|
||||
<el-card shadow="always" class="dialog-card mt-12" v-if="data?.example?.length > 0">
|
||||
<!-- <el-card shadow="always" class="dialog-card mt-12" v-if="data?.example?.length > 0">
|
||||
<h4 class="mb-8">您可以尝试输入以下问题:</h4>
|
||||
<el-space wrap>
|
||||
<template v-for="(item, index) in data?.example" :key="index">
|
||||
@ -31,7 +51,7 @@
|
||||
</div>
|
||||
</template>
|
||||
</el-space>
|
||||
</el-card>
|
||||
</el-card> -->
|
||||
</div>
|
||||
</div>
|
||||
<template v-for="(item, index) in chatList" :key="index">
|
||||
@ -136,6 +156,7 @@ import { ChatManagement, type chatType } from '@/api/type/application'
|
||||
import { randomId } from '@/utils/utils'
|
||||
import useStore from '@/stores'
|
||||
import MdRenderer from '@/components/markdown-renderer/MdRenderer.vue'
|
||||
import { MdPreview } from 'md-editor-v3'
|
||||
defineOptions({ name: 'AiChat' })
|
||||
const route = useRoute()
|
||||
const {
|
||||
@ -168,6 +189,13 @@ const isDisabledChart = computed(
|
||||
() => !(inputValue.value && (props.appId || (props.data?.name && props.data?.model_id)))
|
||||
)
|
||||
|
||||
const prologueList = computed(() => {
|
||||
const temp = props.data?.prologue
|
||||
const lines = temp.split('\n')
|
||||
return lines
|
||||
})
|
||||
const isMdArray = (val: string) => val.match(/^-\s.*/m)
|
||||
|
||||
watch(
|
||||
() => props.record,
|
||||
(value) => {
|
||||
|
||||
@ -12,7 +12,7 @@
|
||||
</div>
|
||||
</slot>
|
||||
</div>
|
||||
<div class="description mt-12" v-if="$slots.description || description">
|
||||
<div class="description pre-line mt-12" v-if="$slots.description || description">
|
||||
<slot name="description">
|
||||
{{ description }}
|
||||
</slot>
|
||||
|
||||
@ -14,7 +14,6 @@ import { MdPreview } from 'md-editor-v3'
|
||||
const props = withDefaults(defineProps<{ source?: string; inner_suffix?: boolean }>(), {
|
||||
source: ''
|
||||
})
|
||||
|
||||
const md_view_list = computed(() => {
|
||||
const temp_source = props.source
|
||||
const temp_md_img_list = temp_source.match(/(!\[.*?\]\(img\/.*?\){.*?})|(!\[.*?\]\(img\/.*?\))/g)
|
||||
|
||||
@ -60,7 +60,7 @@ const datasetRouter = {
|
||||
parentPath: '/dataset/:id',
|
||||
parentName: 'DatasetDetail'
|
||||
},
|
||||
component: () => import('@/views/document/DatasetSetting.vue')
|
||||
component: () => import('@/views/dataset/DatasetSetting.vue')
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
@ -38,6 +38,30 @@ const useDatasetStore = defineStore({
|
||||
reject(error)
|
||||
})
|
||||
})
|
||||
},
|
||||
async asyncGetDatesetDetail(id: string, loading?: Ref<boolean>) {
|
||||
return new Promise((resolve, reject) => {
|
||||
datasetApi
|
||||
.getDatesetDetail(id, loading)
|
||||
.then((data) => {
|
||||
resolve(data)
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error)
|
||||
})
|
||||
})
|
||||
},
|
||||
async asyncSyncDateset(id: string, sync_type: string, loading?: Ref<boolean>) {
|
||||
return new Promise((resolve, reject) => {
|
||||
datasetApi
|
||||
.getSyncWebDateset(id, sync_type, loading)
|
||||
.then((data) => {
|
||||
resolve(data)
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@ -4,5 +4,5 @@
|
||||
@import './element-plus.scss';
|
||||
@import 'nprogress/nprogress.css';
|
||||
@import 'highlight.js/styles/default.css';
|
||||
@import 'md-editor-v3/lib/preview.css';
|
||||
@import 'md-editor-v3/lib/style.css';
|
||||
@import './md-editor.scss';
|
||||
@ -12,6 +12,7 @@
|
||||
<div class="scrollbar-height-left">
|
||||
<el-scrollbar>
|
||||
<el-form
|
||||
hide-required-asterisk
|
||||
ref="applicationFormRef"
|
||||
:model="applicationForm"
|
||||
:rules="rules"
|
||||
@ -20,7 +21,12 @@
|
||||
class="p-24"
|
||||
style="padding-top: 0"
|
||||
>
|
||||
<el-form-item label="应用名称" prop="name">
|
||||
<el-form-item prop="name">
|
||||
<template #label>
|
||||
<div class="flex-between">
|
||||
<span>应用名称 <span class="danger">*</span></span>
|
||||
</div>
|
||||
</template>
|
||||
<el-input
|
||||
v-model="applicationForm.name"
|
||||
maxlength="64"
|
||||
@ -38,10 +44,17 @@
|
||||
show-word-limit
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="选择模型" prop="model_id">
|
||||
<el-form-item prop="model_id">
|
||||
<template #label>
|
||||
<div class="flex-between">
|
||||
<span>AI 模型 <span class="danger">*</span></span>
|
||||
|
||||
<el-button type="primary" link>提示词</el-button>
|
||||
</div>
|
||||
</template>
|
||||
<el-select
|
||||
v-model="applicationForm.model_id"
|
||||
placeholder="请选择模型"
|
||||
placeholder="请选择 AI 模型"
|
||||
style="width: 100%"
|
||||
>
|
||||
<el-option-group
|
||||
@ -86,16 +99,90 @@
|
||||
<template #label>
|
||||
<div class="flex-between">
|
||||
<span>关联知识库</span>
|
||||
<el-button type="primary" link @click="openDatasetDialog">
|
||||
<el-icon class="mr-4"><Plus /></el-icon> 添加
|
||||
</el-button>
|
||||
|
||||
<el-popover :visible="popoverVisible" :width="300" trigger="click">
|
||||
<template #reference>
|
||||
<el-button type="primary" link @click="popoverVisible = !popoverVisible"
|
||||
>参数设置</el-button
|
||||
>
|
||||
</template>
|
||||
<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>
|
||||
<el-tooltip
|
||||
effect="dark"
|
||||
content="相似度越高相关性越强。"
|
||||
placement="right"
|
||||
>
|
||||
<el-icon style="font-size: 16px">
|
||||
<Warning />
|
||||
</el-icon>
|
||||
</el-tooltip>
|
||||
</div>
|
||||
<div @click.stop>
|
||||
高于
|
||||
<el-input-number
|
||||
v-model="formInline.similarity"
|
||||
:min="0"
|
||||
:max="1"
|
||||
:precision="3"
|
||||
:step="0.1"
|
||||
controls-position="right"
|
||||
style="width: 100px"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-item mb-16">
|
||||
<div class="title mb-8">引用分段数</div>
|
||||
<div @click.stop>
|
||||
TOP
|
||||
<el-input-number
|
||||
v-model="formInline.top_number"
|
||||
:min="1"
|
||||
:max="10"
|
||||
controls-position="right"
|
||||
style="width: 100px"
|
||||
size="small"
|
||||
/>
|
||||
个分段
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-item mb-16">
|
||||
<div class="title mb-8">最多引用字符数</div>
|
||||
<div class="flex align-center">
|
||||
<el-slider
|
||||
v-model="formInline.top_number"
|
||||
show-input
|
||||
:show-input-controls="false"
|
||||
:min="500"
|
||||
:max="10000"
|
||||
style="width: 220px"
|
||||
size="small"
|
||||
/>
|
||||
<span class="ml-4">个字符</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-right">
|
||||
<el-button @click="popoverVisible = false" size="small">取消</el-button>
|
||||
<el-button type="primary" @click="popoverVisible = false" size="small"
|
||||
>确认</el-button
|
||||
>
|
||||
</div>
|
||||
</el-popover>
|
||||
</div>
|
||||
</template>
|
||||
<div v-if="applicationForm.dataset_id_list.length == 0">
|
||||
<el-text type="info">关联的知识库展示在这里</el-text>
|
||||
</div>
|
||||
<div class="w-full" v-else>
|
||||
<div class="w-full">
|
||||
<el-row :gutter="12">
|
||||
<el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12" class="mb-8">
|
||||
<CardAdd
|
||||
title="关联知识库"
|
||||
@click="openDatasetDialog"
|
||||
style="min-height: 50px; font-size: 14px"
|
||||
/>
|
||||
</el-col>
|
||||
<el-col
|
||||
:xs="24"
|
||||
:sm="24"
|
||||
@ -126,12 +213,19 @@
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-form-item label="开场白">
|
||||
<el-input
|
||||
<MdEditor
|
||||
class="prologue-md-editor"
|
||||
v-model="applicationForm.prologue"
|
||||
:preview="false"
|
||||
:toolbars="[]"
|
||||
:footers="[]"
|
||||
/>
|
||||
<!-- <el-input
|
||||
v-model="applicationForm.prologue"
|
||||
type="textarea"
|
||||
placeholder="开始对话的欢迎语。您可以这样写:您好,我是 MaxKB 智能小助手,您可以向我提出 MaxKB 产品使用中遇到的任何问题。"
|
||||
:rows="4"
|
||||
/>
|
||||
/> -->
|
||||
</el-form-item>
|
||||
<el-form-item label="示例">
|
||||
<template v-for="(item, index) in exampleList" :key="index">
|
||||
@ -184,6 +278,7 @@ import { groupBy } from 'lodash'
|
||||
import AddDatasetDialog from './components/AddDatasetDialog.vue'
|
||||
import CreateModelDialog from '@/views/template/component/CreateModelDialog.vue'
|
||||
import SelectProviderDialog from '@/views/template/component/SelectProviderDialog.vue'
|
||||
import { MdEditor } from 'md-editor-v3'
|
||||
import applicationApi from '@/api/application'
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
import type { ApplicationFormType } from '@/api/type/application'
|
||||
@ -214,11 +309,20 @@ const applicationForm = ref<ApplicationFormType>({
|
||||
desc: '',
|
||||
model_id: '',
|
||||
multiple_rounds_dialogue: false,
|
||||
prologue: '',
|
||||
prologue: `您好,我是 MaxKB 小助手,您可以向我提出 MaxKB 使用问题。
|
||||
- MaxKB 主要功能有什么?
|
||||
- MaxKB 支持哪些大语言模型?
|
||||
- MaxKB 支持哪些文档类型?`,
|
||||
example: [],
|
||||
dataset_id_list: []
|
||||
})
|
||||
|
||||
const formInline = reactive({
|
||||
similarity: 0.6,
|
||||
top_number: 5
|
||||
})
|
||||
const popoverVisible = ref(false)
|
||||
|
||||
const rules = reactive<FormRules<ApplicationFormType>>({
|
||||
name: [{ required: true, message: '请输入应用名称', trigger: 'blur' }],
|
||||
model_id: [
|
||||
@ -368,4 +472,7 @@ onMounted(() => {
|
||||
position: absolute;
|
||||
right: 10px;
|
||||
}
|
||||
.prologue-md-editor {
|
||||
height: 150px;
|
||||
}
|
||||
</style>
|
||||
|
||||
160
ui/src/views/dataset/DatasetSetting.vue
Normal file
160
ui/src/views/dataset/DatasetSetting.vue
Normal file
@ -0,0 +1,160 @@
|
||||
<template>
|
||||
<LayoutContainer header="设置">
|
||||
<div class="dataset-setting main-calc-height">
|
||||
<el-scrollbar>
|
||||
<div class="p-24" v-loading="loading">
|
||||
<BaseForm ref="BaseFormRef" :data="detail" />
|
||||
|
||||
<el-form
|
||||
ref="webFormRef"
|
||||
:rules="rules"
|
||||
:model="form"
|
||||
label-position="top"
|
||||
require-asterisk-position="right"
|
||||
>
|
||||
<el-form-item label="知识库类型" required>
|
||||
<el-card shadow="never" class="mb-8" v-if="detail.type === '0'">
|
||||
<div class="flex align-center">
|
||||
<el-icon size="32" class="mr-8 info"><Document /></el-icon>
|
||||
<div>
|
||||
<p>通用型</p>
|
||||
<el-text type="info">可以通过上传文件或手动录入方式构建知识库</el-text>
|
||||
</div>
|
||||
</div>
|
||||
</el-card>
|
||||
<el-card shadow="never" class="mb-8" v-if="detail?.type === '1'">
|
||||
<div class="flex align-center">
|
||||
<el-icon size="32" class="mr-8 info"><Monitor /></el-icon>
|
||||
<div>
|
||||
<p>Web 站点</p>
|
||||
<el-text type="info"> 通过网站链接同步方式构建知识库 </el-text>
|
||||
</div>
|
||||
</div>
|
||||
</el-card>
|
||||
</el-form-item>
|
||||
<el-form-item label="Web 根地址" prop="source_url" v-if="detail.type === '1'">
|
||||
<el-input
|
||||
v-model="form.source_url"
|
||||
placeholder="请输入 Web 根地址"
|
||||
@blur="form.source_url = form.source_url.trim()"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="选择器" v-if="detail.type === '1'">
|
||||
<el-input
|
||||
v-model="form.selector"
|
||||
placeholder="请输入选择器"
|
||||
@blur="form.selector = form.selector.trim()"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<h4 class="title-decoration-1 mb-16">关联应用</h4>
|
||||
|
||||
<el-row :gutter="12">
|
||||
<el-col :span="12" v-for="(item, index) in application_list" :key="index" class="mb-16">
|
||||
<CardCheckbox value-field="id" :data="item" v-model="application_id_list">
|
||||
<template #icon>
|
||||
<AppAvatar
|
||||
v-if="item.name"
|
||||
:name="item.name"
|
||||
pinyinColor
|
||||
class="mr-12"
|
||||
shape="square"
|
||||
:size="32"
|
||||
/>
|
||||
</template>
|
||||
{{ item.name }}
|
||||
</CardCheckbox>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<div class="text-right">
|
||||
<el-button @click="submit" type="primary"> 保存 </el-button>
|
||||
</div>
|
||||
</div>
|
||||
</el-scrollbar>
|
||||
</div>
|
||||
</LayoutContainer>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted, reactive } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import BaseForm from '@/views/dataset/component/BaseForm.vue'
|
||||
import datasetApi from '@/api/dataset'
|
||||
import type { ApplicationFormType } from '@/api/type/application'
|
||||
import { MsgSuccess } from '@/utils/message'
|
||||
import useStore from '@/stores'
|
||||
const route = useRoute()
|
||||
const {
|
||||
params: { id }
|
||||
} = route as any
|
||||
|
||||
const { dataset } = useStore()
|
||||
const webFormRef = ref()
|
||||
const BaseFormRef = ref()
|
||||
const loading = ref(false)
|
||||
const detail = ref<any>({})
|
||||
const application_list = ref<Array<ApplicationFormType>>([])
|
||||
const application_id_list = ref([])
|
||||
const form = ref<any>({
|
||||
source_url: '',
|
||||
selector: ''
|
||||
})
|
||||
|
||||
const rules = reactive({
|
||||
source_url: [{ required: true, message: '请输入 Web 根地址', trigger: 'blur' }]
|
||||
})
|
||||
|
||||
async function submit() {
|
||||
if (await BaseFormRef.value?.validate()) {
|
||||
await webFormRef.value.validate((valid: any) => {
|
||||
if (valid) {
|
||||
loading.value = true
|
||||
const obj =
|
||||
detail.value.type === '1'
|
||||
? {
|
||||
...BaseFormRef.value.form,
|
||||
...form.value
|
||||
}
|
||||
: {
|
||||
application_id_list: application_id_list.value,
|
||||
...BaseFormRef.value.form
|
||||
}
|
||||
datasetApi
|
||||
.putDateset(id, obj)
|
||||
.then((res) => {
|
||||
MsgSuccess('保存成功')
|
||||
loading.value = false
|
||||
})
|
||||
.catch(() => {
|
||||
loading.value = false
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function getDetail() {
|
||||
dataset.asyncGetDatesetDetail(id, loading).then((res: any) => {
|
||||
detail.value = res.data
|
||||
if (detail.value.type === '1') {
|
||||
form.value = res.data.meta
|
||||
}
|
||||
|
||||
application_id_list.value = res.data?.application_id_list
|
||||
datasetApi.listUsableApplication(id, loading).then((ok) => {
|
||||
application_list.value = ok.data
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
getDetail()
|
||||
})
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
.dataset-setting {
|
||||
width: 70%;
|
||||
margin: 0 auto;
|
||||
}
|
||||
</style>
|
||||
87
ui/src/views/dataset/component/SyncWebDialog.vue
Normal file
87
ui/src/views/dataset/component/SyncWebDialog.vue
Normal file
@ -0,0 +1,87 @@
|
||||
<template>
|
||||
<el-dialog
|
||||
title="同步知识库"
|
||||
v-model="dialogVisible"
|
||||
width="600px"
|
||||
:close-on-click-modal="false"
|
||||
:close-on-press-escape="false"
|
||||
:destroy-on-close="true"
|
||||
>
|
||||
<p class="mb-8">同步方式</p>
|
||||
<el-radio-group v-model="method" class="card__radio">
|
||||
<el-card shadow="never" class="mb-16" :class="method === 'replace' ? 'active' : ''">
|
||||
<el-radio label="replace" size="large">
|
||||
<p class="mb-4">替换同步</p>
|
||||
<el-text type="info">重新获取 Web 站点文档,覆盖替换本地知识库中的文档</el-text>
|
||||
</el-radio>
|
||||
</el-card>
|
||||
|
||||
<el-card shadow="never" class="mb-16" :class="method === 'complete' ? 'active' : ''">
|
||||
<el-radio label="complete" size="large">
|
||||
<p class="mb-4">整体同步</p>
|
||||
<el-text type="info">先删除本地知识库所有文档,重新获取 Web 站点文档</el-text>
|
||||
</el-radio>
|
||||
</el-card>
|
||||
</el-radio-group>
|
||||
<p class="danger">注意:所有同步都会删除已有数据重新获取新数据,请谨慎操作。</p>
|
||||
<template #footer>
|
||||
<span class="dialog-footer">
|
||||
<el-button @click.prevent="dialogVisible = false"> 取消 </el-button>
|
||||
<el-button type="primary" @click="submit" :loading="loading"> 确定 </el-button>
|
||||
</span>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { ref, watch } from 'vue'
|
||||
|
||||
import { MsgSuccess } from '@/utils/message'
|
||||
|
||||
import useStore from '@/stores'
|
||||
const { dataset } = useStore()
|
||||
|
||||
const emit = defineEmits(['refresh'])
|
||||
const loading = ref<boolean>(false)
|
||||
const method = ref('replace')
|
||||
const datasetId = ref('')
|
||||
|
||||
const dialogVisible = ref<boolean>(false)
|
||||
|
||||
watch(dialogVisible, (bool) => {
|
||||
if (!bool) {
|
||||
method.value = 'replace'
|
||||
}
|
||||
})
|
||||
|
||||
const open = (id: string) => {
|
||||
datasetId.value = id
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
const submit = () => {
|
||||
dataset.asyncSyncDateset(datasetId.value, method.value, loading).then((res: any) => {
|
||||
emit('refresh', res.data)
|
||||
dialogVisible.value = false
|
||||
})
|
||||
}
|
||||
|
||||
defineExpose({ open })
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
.select-provider {
|
||||
font-size: 16px;
|
||||
color: rgba(100, 106, 115, 1);
|
||||
font-weight: 400;
|
||||
line-height: 24px;
|
||||
cursor: pointer;
|
||||
&:hover {
|
||||
color: var(--el-color-primary);
|
||||
}
|
||||
}
|
||||
.active-breadcrumb {
|
||||
font-size: 16px;
|
||||
color: rgba(31, 35, 41, 1);
|
||||
font-weight: 500;
|
||||
line-height: 24px;
|
||||
}
|
||||
</style>
|
||||
@ -53,7 +53,12 @@
|
||||
</span>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item icon="Refresh" v-if="item.type === '1'">同步</el-dropdown-item>
|
||||
<el-dropdown-item
|
||||
icon="Refresh"
|
||||
@click.stop="syncDataset(item)"
|
||||
v-if="item.type === '1'"
|
||||
>同步</el-dropdown-item
|
||||
>
|
||||
<el-dropdown-item
|
||||
icon="Setting"
|
||||
@click.stop="router.push({ path: `/dataset/${item.id}/setting` })"
|
||||
@ -74,16 +79,19 @@
|
||||
</el-row>
|
||||
</InfiniteScroll>
|
||||
</div>
|
||||
<SyncWebDialog ref="SyncWebDialogRef" @refresh="refresh" />
|
||||
</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted, reactive, computed } from 'vue'
|
||||
import SyncWebDialog from '@/views/dataset/component/SyncWebDialog.vue'
|
||||
import datasetApi from '@/api/dataset'
|
||||
import { MsgSuccess, MsgConfirm } from '@/utils/message'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { numberFormat } from '@/utils/utils'
|
||||
const router = useRouter()
|
||||
|
||||
const SyncWebDialogRef = ref()
|
||||
const loading = ref(false)
|
||||
const datasetList = ref<any[]>([])
|
||||
const paginationConfig = reactive({
|
||||
@ -94,6 +102,15 @@ const paginationConfig = reactive({
|
||||
|
||||
const searchValue = ref('')
|
||||
|
||||
function refresh(row: any) {
|
||||
const index = datasetList.value.findIndex((v) => v.id === row.id)
|
||||
datasetList.value.splice(index, 1, row)
|
||||
}
|
||||
|
||||
function syncDataset(row: any) {
|
||||
SyncWebDialogRef.value.open(row.id)
|
||||
}
|
||||
|
||||
function searchHandle() {
|
||||
paginationConfig.current_page = 1
|
||||
datasetList.value = []
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
<!-- 基本信息 -->
|
||||
<BaseForm ref="BaseFormRef" v-if="isCreate" />
|
||||
<el-form
|
||||
v-if="isCreate"
|
||||
ref="webFormRef"
|
||||
:rules="rules"
|
||||
:model="form"
|
||||
@ -42,11 +43,11 @@
|
||||
</el-row>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item label="Web 根地址" prop="url" v-if="form.type === '1'">
|
||||
<el-form-item label="Web 根地址" prop="source_url" v-if="form.type === '1'">
|
||||
<el-input
|
||||
v-model="form.url"
|
||||
v-model="form.source_url"
|
||||
placeholder="请输入 Web 根地址"
|
||||
@blur="form.url = form.url.trim()"
|
||||
@blur="form.source_url = form.source_url.trim()"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="选择器" v-if="form.type === '1'">
|
||||
@ -87,12 +88,12 @@ const loading = ref(false)
|
||||
|
||||
const form = ref<any>({
|
||||
type: '0',
|
||||
url: '',
|
||||
source_url: '',
|
||||
selector: ''
|
||||
})
|
||||
|
||||
const rules = reactive({
|
||||
url: [{ required: true, message: '请输入 Web 根地址', trigger: 'blur' }]
|
||||
source_url: [{ required: true, message: '请输入 Web 根地址', trigger: 'blur' }]
|
||||
})
|
||||
|
||||
watch(form.value, (value) => {
|
||||
@ -105,7 +106,7 @@ watch(form.value, (value) => {
|
||||
|
||||
function radioChange() {
|
||||
dataset.saveDocumentsFile([])
|
||||
form.value.url = ''
|
||||
form.value.source_url = ''
|
||||
form.value.selector = ''
|
||||
}
|
||||
|
||||
|
||||
@ -42,7 +42,14 @@
|
||||
</el-tooltip>
|
||||
</div>
|
||||
<div @click.stop>
|
||||
<el-select v-model="form.patterns" multiple placeholder="请选择">
|
||||
<el-select
|
||||
v-model="form.patterns"
|
||||
multiple
|
||||
allow-create
|
||||
default-first-option
|
||||
filterable
|
||||
placeholder="请选择"
|
||||
>
|
||||
<el-option
|
||||
v-for="(item, index) in splitPatternList"
|
||||
:key="index"
|
||||
|
||||
@ -1,100 +0,0 @@
|
||||
<template>
|
||||
<LayoutContainer header="设置">
|
||||
<div class="dataset-setting main-calc-height">
|
||||
<el-scrollbar>
|
||||
<div class="p-24" v-loading="loading">
|
||||
<BaseForm ref="BaseFormRef" :data="detail" />
|
||||
|
||||
<h4 class="title-decoration-1 mb-16">关联应用</h4>
|
||||
|
||||
<el-row :gutter="12">
|
||||
<el-col :span="12" v-for="(item, index) in application_list" :key="index" class="mb-16">
|
||||
<CardCheckbox value-field="id" :data="item" v-model="application_id_list">
|
||||
<template #icon>
|
||||
<AppAvatar
|
||||
v-if="item.name"
|
||||
:name="item.name"
|
||||
pinyinColor
|
||||
class="mr-12"
|
||||
shape="square"
|
||||
:size="32"
|
||||
/>
|
||||
</template>
|
||||
{{ item.name }}
|
||||
</CardCheckbox>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<div class="text-right">
|
||||
<el-button @click="submit" type="primary"> 保存 </el-button>
|
||||
</div>
|
||||
</div>
|
||||
</el-scrollbar>
|
||||
</div>
|
||||
</LayoutContainer>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import BaseForm from '@/views/dataset/component/BaseForm.vue'
|
||||
import datasetApi from '@/api/dataset'
|
||||
import type { ApplicationFormType } from '@/api/type/application'
|
||||
import { MsgSuccess } from '@/utils/message'
|
||||
const route = useRoute()
|
||||
const {
|
||||
params: { id }
|
||||
} = route as any
|
||||
|
||||
const BaseFormRef = ref()
|
||||
const loading = ref(false)
|
||||
const detail = ref({})
|
||||
|
||||
const application_list = ref<Array<ApplicationFormType>>([])
|
||||
const application_id_list = ref([])
|
||||
|
||||
async function submit() {
|
||||
if (await BaseFormRef.value?.validate()) {
|
||||
loading.value = true
|
||||
const obj = {
|
||||
application_id_list: application_id_list.value,
|
||||
...BaseFormRef.value.form
|
||||
}
|
||||
datasetApi
|
||||
.putDateset(id, obj)
|
||||
.then((res) => {
|
||||
MsgSuccess('保存成功')
|
||||
loading.value = false
|
||||
})
|
||||
.catch(() => {
|
||||
loading.value = false
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function getDetail() {
|
||||
loading.value = true
|
||||
datasetApi
|
||||
.getDatesetDetail(id)
|
||||
.then((res) => {
|
||||
detail.value = res.data
|
||||
application_id_list.value = res.data?.application_id_list
|
||||
datasetApi.listUsableApplication(id, loading).then((ok) => {
|
||||
application_list.value = ok.data
|
||||
loading.value = false
|
||||
})
|
||||
})
|
||||
.catch(() => {
|
||||
loading.value = false
|
||||
})
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
getDetail()
|
||||
})
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
.dataset-setting {
|
||||
width: 70%;
|
||||
margin: 0 auto;
|
||||
}
|
||||
</style>
|
||||
88
ui/src/views/document/component/ImportDocumentDialog.vue
Normal file
88
ui/src/views/document/component/ImportDocumentDialog.vue
Normal file
@ -0,0 +1,88 @@
|
||||
<template>
|
||||
<el-dialog
|
||||
title="同步知识库"
|
||||
v-model="dialogVisible"
|
||||
width="600px"
|
||||
:close-on-click-modal="false"
|
||||
:close-on-press-escape="false"
|
||||
:destroy-on-close="true"
|
||||
>
|
||||
<p class="mb-8">同步方式</p>
|
||||
<el-radio-group v-model="method" class="card__radio">
|
||||
<el-card shadow="never" class="mb-16" :class="method === 'replace' ? 'active' : ''">
|
||||
<el-radio label="replace" size="large">
|
||||
<p class="mb-4">替换同步</p>
|
||||
<el-text type="info">重新获取 Web 站点文档,覆盖替换本地知识库中的文档</el-text>
|
||||
</el-radio>
|
||||
</el-card>
|
||||
|
||||
<el-card shadow="never" class="mb-16" :class="method === 'complete' ? 'active' : ''">
|
||||
<el-radio label="complete" size="large">
|
||||
<p class="mb-4">整体同步</p>
|
||||
<el-text type="info">先删除本地知识库所有文档,重新获取 Web 站点文档</el-text>
|
||||
</el-radio>
|
||||
</el-card>
|
||||
</el-radio-group>
|
||||
<p class="danger">注意:所有同步都会删除已有数据重新获取新数据,请谨慎操作。</p>
|
||||
<template #footer>
|
||||
<span class="dialog-footer">
|
||||
<el-button @click.prevent="dialogVisible = false"> 取消 </el-button>
|
||||
<el-button type="primary" @click="submit" :loading="loading"> 确定 </el-button>
|
||||
</span>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { ref, watch } from 'vue'
|
||||
|
||||
import { MsgSuccess } from '@/utils/message'
|
||||
|
||||
import useStore from '@/stores'
|
||||
const { dataset } = useStore()
|
||||
|
||||
const emit = defineEmits(['refresh'])
|
||||
const loading = ref<boolean>(false)
|
||||
const method = ref('replace')
|
||||
const datasetId = ref('')
|
||||
|
||||
const dialogVisible = ref<boolean>(false)
|
||||
|
||||
watch(dialogVisible, (bool) => {
|
||||
if (!bool) {
|
||||
method.value = 'replace'
|
||||
}
|
||||
})
|
||||
|
||||
const open = (id: string) => {
|
||||
datasetId.value = id
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
const submit = () => {
|
||||
dataset.asyncSyncDateset(datasetId.value, method.value, loading).then((res: any) => {
|
||||
// MsgSuccess('删除成功')
|
||||
emit('refresh', res.data)
|
||||
dialogVisible.value = false
|
||||
})
|
||||
}
|
||||
|
||||
defineExpose({ open })
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
.select-provider {
|
||||
font-size: 16px;
|
||||
color: rgba(100, 106, 115, 1);
|
||||
font-weight: 400;
|
||||
line-height: 24px;
|
||||
cursor: pointer;
|
||||
&:hover {
|
||||
color: var(--el-color-primary);
|
||||
}
|
||||
}
|
||||
.active-breadcrumb {
|
||||
font-size: 16px;
|
||||
color: rgba(31, 35, 41, 1);
|
||||
font-weight: 500;
|
||||
line-height: 24px;
|
||||
}
|
||||
</style>
|
||||
@ -3,11 +3,18 @@
|
||||
<div class="main-calc-height">
|
||||
<div class="p-24">
|
||||
<div class="flex-between">
|
||||
<el-button
|
||||
type="primary"
|
||||
@click="router.push({ path: '/dataset/upload', query: { id: id } })"
|
||||
>上传文档</el-button
|
||||
>
|
||||
<div>
|
||||
<el-button
|
||||
v-if="datasetDetail.type === '0'"
|
||||
type="primary"
|
||||
@click="router.push({ path: '/dataset/upload', query: { id: id } })"
|
||||
>上传文档</el-button
|
||||
>
|
||||
<el-button v-if="datasetDetail.type === '1'" type="primary">导入文档</el-button>
|
||||
<!-- <el-button v-if="datasetDetail.type === '1'">批量同步</el-button> -->
|
||||
<el-button :disabled="multipleSelection.length === 0">批量删除</el-button>
|
||||
</div>
|
||||
|
||||
<el-input
|
||||
v-model="filterText"
|
||||
placeholder="按 文档名称 搜索"
|
||||
@ -17,18 +24,21 @@
|
||||
/>
|
||||
</div>
|
||||
<app-table
|
||||
ref="multipleTableRef"
|
||||
class="mt-16"
|
||||
:data="documentData"
|
||||
:pagination-config="paginationConfig"
|
||||
quick-create
|
||||
:quick-create="datasetDetail.type === '0'"
|
||||
@sizeChange="handleSizeChange"
|
||||
@changePage="getList"
|
||||
@cell-mouse-enter="cellMouseEnter"
|
||||
@cell-mouse-leave="cellMouseLeave"
|
||||
@creatQuick="creatQuickHandle"
|
||||
@row-click="rowClickHandle"
|
||||
@selection-change="handleSelectionChange"
|
||||
v-loading="loading"
|
||||
>
|
||||
<el-table-column type="selection" width="55" />
|
||||
<el-table-column prop="name" label="文件名称" min-width="280">
|
||||
<template #default="{ row }">
|
||||
<ReadWrite
|
||||
@ -80,20 +90,49 @@
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" align="center">
|
||||
<template #default="{ row }">
|
||||
<span v-if="row.status === '2'" class="mr-4">
|
||||
<el-tooltip effect="dark" content="重试" placement="top">
|
||||
<div v-if="datasetDetail.type === '0'">
|
||||
<span v-if="row.status === '2'" class="mr-4">
|
||||
<el-tooltip effect="dark" content="重试" placement="top">
|
||||
<el-button type="primary" text @click.stop="refreshDocument(row)">
|
||||
<el-icon><RefreshRight /></el-icon>
|
||||
</el-button>
|
||||
</el-tooltip>
|
||||
</span>
|
||||
<span>
|
||||
<el-tooltip effect="dark" content="删除" placement="top">
|
||||
<el-button type="primary" text @click.stop="deleteDocument(row)">
|
||||
<el-icon><Delete /></el-icon>
|
||||
</el-button>
|
||||
</el-tooltip>
|
||||
</span>
|
||||
</div>
|
||||
<div v-if="datasetDetail.type === '1'">
|
||||
<el-tooltip
|
||||
effect="dark"
|
||||
content="同步"
|
||||
placement="top"
|
||||
v-if="datasetDetail.type === '1'"
|
||||
>
|
||||
<el-button type="primary" text @click.stop="refreshDocument(row)">
|
||||
<el-icon><RefreshRight /></el-icon>
|
||||
<el-icon><Refresh /></el-icon>
|
||||
</el-button>
|
||||
</el-tooltip>
|
||||
</span>
|
||||
<span>
|
||||
<el-tooltip effect="dark" content="删除" placement="top">
|
||||
<el-button type="primary" text @click.stop="deleteDocument(row)">
|
||||
<el-icon><Delete /></el-icon>
|
||||
</el-button>
|
||||
</el-tooltip>
|
||||
</span>
|
||||
<span @click.stop>
|
||||
<el-dropdown trigger="click">
|
||||
<span class="el-dropdown-link cursor">
|
||||
<el-icon><MoreFilled /></el-icon>
|
||||
</span>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item icon="Setting">设置</el-dropdown-item>
|
||||
<el-dropdown-item icon="Delete" @click.stop="deleteDocument(row)"
|
||||
>删除</el-dropdown-item
|
||||
>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</app-table>
|
||||
@ -104,21 +143,25 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted, reactive, onBeforeUnmount } from 'vue'
|
||||
import { useRouter, useRoute } from 'vue-router'
|
||||
import { ElTable } from 'element-plus'
|
||||
import documentApi from '@/api/document'
|
||||
import { numberFormat } from '@/utils/utils'
|
||||
import { datetimeFormat } from '@/utils/time'
|
||||
import { MsgSuccess, MsgConfirm } from '@/utils/message'
|
||||
import useStore from '@/stores'
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
const {
|
||||
params: { id }
|
||||
} = route as any
|
||||
|
||||
const { dataset } = useStore()
|
||||
const loading = ref(false)
|
||||
let interval: any
|
||||
const filterText = ref('')
|
||||
const documentData = ref<any[]>([])
|
||||
const currentMouseId = ref(null)
|
||||
const datasetDetail = ref<any>({})
|
||||
|
||||
const paginationConfig = reactive({
|
||||
current_page: 1,
|
||||
@ -126,6 +169,13 @@ const paginationConfig = reactive({
|
||||
total: 0
|
||||
})
|
||||
|
||||
const multipleTableRef = ref<InstanceType<typeof ElTable>>()
|
||||
const multipleSelection = ref<any[]>([])
|
||||
|
||||
const handleSelectionChange = (val: any[]) => {
|
||||
multipleSelection.value = val
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化轮询
|
||||
*/
|
||||
@ -258,7 +308,14 @@ function getList(bool?: boolean) {
|
||||
})
|
||||
}
|
||||
|
||||
function getDetail() {
|
||||
dataset.asyncGetDatesetDetail(id, loading).then((res: any) => {
|
||||
datasetDetail.value = res.data
|
||||
})
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
getDetail()
|
||||
getList()
|
||||
// 初始化定时任务
|
||||
initInterval()
|
||||
|
||||
@ -44,7 +44,7 @@
|
||||
<template #icon>
|
||||
<AppAvatar :name="index + 1 + ''" class="mr-12 avatar-light" :size="22" />
|
||||
</template>
|
||||
<div class="active-button primary">{{ (item.similarity * 100).toFixed(2) }}%</div>
|
||||
<div class="active-button primary">{{ item.similarity.toFixed(3) }}</div>
|
||||
<template #footer>
|
||||
<div class="footer-content flex-between">
|
||||
<el-text>
|
||||
@ -75,7 +75,7 @@
|
||||
<ParagraphDialog ref="ParagraphDialogRef" :title="title" @refresh="refresh" />
|
||||
</LayoutContainer>
|
||||
<div class="hit-test__operate p-24 pt-0">
|
||||
<el-popover :visible="popoverVisible" placement="top-start" :width="560" trigger="click">
|
||||
<el-popover :visible="popoverVisible" placement="top-start" :width="600" trigger="click">
|
||||
<template #reference>
|
||||
<el-button icon="Setting" class="mb-8" @click="popoverVisible = !popoverVisible"
|
||||
>参数设置</el-button
|
||||
@ -83,15 +83,16 @@
|
||||
</template>
|
||||
<div class="flex">
|
||||
<div>
|
||||
相似度
|
||||
相似度高于
|
||||
<el-input-number
|
||||
v-model="formInline.similarity"
|
||||
:min="1"
|
||||
:max="100"
|
||||
:min="0"
|
||||
:max="1"
|
||||
:precision="3"
|
||||
:step="0.1"
|
||||
controls-position="right"
|
||||
style="width: 100px"
|
||||
/>
|
||||
%
|
||||
</div>
|
||||
|
||||
<div class="ml-16">
|
||||
@ -156,7 +157,7 @@ const paragraphDetail = ref<any[]>([])
|
||||
const title = ref('')
|
||||
const inputValue = ref('')
|
||||
const formInline = reactive({
|
||||
similarity: 60,
|
||||
similarity: 0.600,
|
||||
top_number: 5
|
||||
})
|
||||
const popoverVisible = ref(false)
|
||||
@ -193,7 +194,7 @@ function sendChatHandle(event: any) {
|
||||
function getHitTestList() {
|
||||
const obj = {
|
||||
query_text: inputValue.value,
|
||||
similarity: formInline.similarity / 100,
|
||||
similarity: formInline.similarity,
|
||||
top_number: formInline.top_number
|
||||
}
|
||||
if (isDataset.value) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user