mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-26 01:33:05 +00:00
feat: 文档批量设置命中处理方式 (#293)
This commit is contained in:
parent
d1fe18166a
commit
5705f3c4a8
|
|
@ -713,6 +713,19 @@ class DocumentSerializers(ApiMixin, serializers.Serializer):
|
|||
ListenerManagement.delete_embedding_by_document_list_signal.send(document_id_list)
|
||||
return True
|
||||
|
||||
def batch_edit_hit_handling(self, instance: Dict, with_valid=True):
|
||||
if with_valid:
|
||||
BatchSerializer(data=instance).is_valid(model=Document, raise_exception=True)
|
||||
hit_handling_method = instance.get('hit_handling_method')
|
||||
if hit_handling_method is None:
|
||||
raise AppApiException(500, '命中处理方式必填')
|
||||
if hit_handling_method != 'optimization' and hit_handling_method != 'directly_return':
|
||||
raise AppApiException(500, '命中处理方式必须为directly_return|optimization')
|
||||
self.is_valid(raise_exception=True)
|
||||
document_id_list = instance.get("id_list")
|
||||
hit_handling_method = instance.get('hit_handling_method')
|
||||
QuerySet(Document).filter(id__in=document_id_list).update(hit_handling_method=hit_handling_method)
|
||||
|
||||
|
||||
class FileBufferHandle:
|
||||
buffer = None
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
# coding=utf-8
|
||||
"""
|
||||
@project: maxkb
|
||||
@Author:虎
|
||||
@file: document_api.py
|
||||
@date:2024/4/28 13:56
|
||||
@desc:
|
||||
"""
|
||||
from drf_yasg import openapi
|
||||
|
||||
from common.mixins.api_mixin import ApiMixin
|
||||
|
||||
|
||||
class DocumentApi(ApiMixin):
|
||||
class BatchEditHitHandlingApi(ApiMixin):
|
||||
@staticmethod
|
||||
def get_request_body_api():
|
||||
return openapi.Schema(
|
||||
type=openapi.TYPE_OBJECT,
|
||||
properties={
|
||||
'id_list': openapi.Schema(type=openapi.TYPE_ARRAY, items=openapi.Schema(type=openapi.TYPE_STRING),
|
||||
title="主键id列表",
|
||||
description="主键id列表"),
|
||||
'hit_handling_method': openapi.Schema(type=openapi.TYPE_STRING, title="命中处理方式",
|
||||
description="directly_return|optimization")
|
||||
}
|
||||
)
|
||||
|
|
@ -14,6 +14,7 @@ urlpatterns = [
|
|||
path('dataset/<str:dataset_id>/document', views.Document.as_view(), name='document'),
|
||||
path('dataset/<str:dataset_id>/document/web', views.WebDocument.as_view()),
|
||||
path('dataset/<str:dataset_id>/document/_bach', views.Document.Batch.as_view()),
|
||||
path('dataset/<str:dataset_id>/document/batch_hit_handling', views.Document.BatchEditHitHandling.as_view()),
|
||||
path('dataset/<str:dataset_id>/document/<int:current_page>/<int:page_size>', views.Document.Page.as_view()),
|
||||
path('dataset/<str:dataset_id>/document/<str:document_id>', views.Document.Operate.as_view(),
|
||||
name="document_operate"),
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ from common.response import result
|
|||
from common.util.common import query_params_to_single_dict
|
||||
from dataset.serializers.common_serializers import BatchSerializer
|
||||
from dataset.serializers.document_serializers import DocumentSerializers, DocumentWebInstanceSerializer
|
||||
from dataset.swagger_api.document_api import DocumentApi
|
||||
|
||||
|
||||
class WebDocument(APIView):
|
||||
|
|
@ -71,6 +72,24 @@ class Document(APIView):
|
|||
d.is_valid(raise_exception=True)
|
||||
return result.success(d.list())
|
||||
|
||||
class BatchEditHitHandling(APIView):
|
||||
authentication_classes = [TokenAuth]
|
||||
|
||||
@action(methods=['POST'], detail=False)
|
||||
@swagger_auto_schema(operation_summary="批量修改文档命中处理方式",
|
||||
operation_id="批量修改文档命中处理方式",
|
||||
request_body=
|
||||
DocumentApi.BatchEditHitHandlingApi.get_request_body_api(),
|
||||
manual_parameters=DocumentSerializers.Create.get_request_params_api(),
|
||||
responses=result.get_default_response(),
|
||||
tags=["知识库/文档"])
|
||||
@has_permissions(
|
||||
lambda r, k: Permission(group=Group.DATASET, operate=Operate.MANAGE,
|
||||
dynamic_tag=k.get('dataset_id')))
|
||||
def put(self, request: Request, dataset_id: str):
|
||||
return result.success(
|
||||
DocumentSerializers.Batch(data={'dataset_id': dataset_id}).batch_edit_hit_handling(request.data))
|
||||
|
||||
class Batch(APIView):
|
||||
authentication_classes = [TokenAuth]
|
||||
|
||||
|
|
|
|||
|
|
@ -206,6 +206,20 @@ const putMigrateMulDocument: (
|
|||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量修改命中方式
|
||||
* @param dataset_id 知识库id
|
||||
* @param data {id_list:[],hit_handling_method:'directly_return|optimization'}
|
||||
* @param loading
|
||||
* @returns
|
||||
*/
|
||||
const batchEditHitHandling: (
|
||||
dataset_id: string,
|
||||
data: any,
|
||||
loading?: Ref<boolean>
|
||||
) => Promise<Result<boolean>> = (dataset_id, data, loading) => {
|
||||
return put(`${prefix}/${dataset_id}/document/batch_hit_handling`, data, undefined, loading)
|
||||
}
|
||||
export default {
|
||||
postSplitDocument,
|
||||
getDocument,
|
||||
|
|
@ -219,5 +233,6 @@ export default {
|
|||
putDocumentRefresh,
|
||||
delMulSyncDocument,
|
||||
postWebDocument,
|
||||
putMigrateMulDocument
|
||||
putMigrateMulDocument,
|
||||
batchEditHitHandling
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,96 @@
|
|||
<template>
|
||||
<el-dialog
|
||||
title="设置"
|
||||
v-model="dialogVisible"
|
||||
:close-on-click-modal="false"
|
||||
:close-on-press-escape="false"
|
||||
:destroy-on-close="true"
|
||||
width="400"
|
||||
>
|
||||
<el-form
|
||||
label-position="top"
|
||||
ref="webFormRef"
|
||||
:rules="rules"
|
||||
:model="form"
|
||||
require-asterisk-position="right"
|
||||
>
|
||||
<el-form-item>
|
||||
<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>
|
||||
<el-radio-group v-model="form.hit_handling_method">
|
||||
<template v-for="(value, key) of hitHandlingMethod" :key="key">
|
||||
<el-radio :value="key">{{ value }}</el-radio>
|
||||
</template>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<span class="dialog-footer">
|
||||
<el-button @click.prevent="dialogVisible = false"> 取消 </el-button>
|
||||
<el-button type="primary" @click="submit(webFormRef)" :loading="loading"> 确定 </el-button>
|
||||
</span>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, watch } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
import documentApi from '@/api/document'
|
||||
import { MsgSuccess } from '@/utils/message'
|
||||
import { hitHandlingMethod } from '../utils'
|
||||
|
||||
const route = useRoute()
|
||||
const {
|
||||
params: { id }
|
||||
} = route as any
|
||||
|
||||
const emit = defineEmits(['refresh'])
|
||||
const webFormRef = ref()
|
||||
const loading = ref<boolean>(false)
|
||||
const documentList = ref<Array<string>>([])
|
||||
const form = ref<any>({
|
||||
hit_handling_method: 'optimization'
|
||||
})
|
||||
|
||||
const rules = reactive({
|
||||
source_url: [{ required: true, message: '请输入文档地址', trigger: 'blur' }]
|
||||
})
|
||||
|
||||
const dialogVisible = ref<boolean>(false)
|
||||
|
||||
const open = (list: Array<string>) => {
|
||||
documentList.value = list
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
const submit = async (formEl: FormInstance | undefined) => {
|
||||
if (!formEl) return
|
||||
await formEl.validate((valid, fields) => {
|
||||
if (valid) {
|
||||
const obj = {
|
||||
hit_handling_method: form.value.hit_handling_method,
|
||||
id_list: documentList.value
|
||||
}
|
||||
documentApi.batchEditHitHandling(id, obj, loading).then((res: any) => {
|
||||
MsgSuccess('设置成功')
|
||||
emit('refresh')
|
||||
dialogVisible.value = false
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
defineExpose({ open })
|
||||
</script>
|
||||
<style lang="scss" scoped></style>
|
||||
|
|
@ -21,10 +21,13 @@
|
|||
>同步文档</el-button
|
||||
>
|
||||
<el-button @click="openDatasetDialog()" :disabled="multipleSelection.length === 0"
|
||||
>批量迁移</el-button
|
||||
>迁移</el-button
|
||||
>
|
||||
<el-button @click="openBatchEditDocument" :disabled="multipleSelection.length === 0"
|
||||
>设置</el-button
|
||||
>
|
||||
<el-button @click="deleteMulDocument" :disabled="multipleSelection.length === 0"
|
||||
>批量删除</el-button
|
||||
>删除</el-button
|
||||
>
|
||||
</div>
|
||||
|
||||
|
|
@ -212,6 +215,10 @@
|
|||
</div>
|
||||
<ImportDocumentDialog ref="ImportDocumentDialogRef" :title="title" @refresh="refresh" />
|
||||
<SyncWebDialog ref="SyncWebDialogRef" @refresh="refresh" />
|
||||
<BatchEditDocumentDialog
|
||||
ref="batchEditDocumentDialogRef"
|
||||
@refresh="refresh"
|
||||
></BatchEditDocumentDialog>
|
||||
<!-- 选择知识库 -->
|
||||
<SelectDatasetDialog ref="SelectDatasetDialogRef" @refresh="refresh" />
|
||||
</div>
|
||||
|
|
@ -225,6 +232,7 @@ import documentApi from '@/api/document'
|
|||
import ImportDocumentDialog from './component/ImportDocumentDialog.vue'
|
||||
import SyncWebDialog from '@/views/dataset/component/SyncWebDialog.vue'
|
||||
import SelectDatasetDialog from './component/SelectDatasetDialog.vue'
|
||||
import BatchEditDocumentDialog from './component/BatchEditDocumentDialog.vue'
|
||||
import { numberFormat } from '@/utils/utils'
|
||||
import { datetimeFormat } from '@/utils/time'
|
||||
import { hitHandlingMethod } from './utils'
|
||||
|
|
@ -257,7 +265,7 @@ onBeforeRouteLeave((to: any, from: any) => {
|
|||
})
|
||||
const beforePagination = computed(() => common.paginationConfig[storeKey])
|
||||
const beforeSearch = computed(() => common.search[storeKey])
|
||||
|
||||
const batchEditDocumentDialogRef = ref<InstanceType<typeof BatchEditDocumentDialog>>()
|
||||
const SyncWebDialogRef = ref()
|
||||
const loading = ref(false)
|
||||
let interval: any
|
||||
|
|
@ -317,6 +325,13 @@ const handleSelectionChange = (val: any[]) => {
|
|||
multipleSelection.value = val
|
||||
}
|
||||
|
||||
function openBatchEditDocument() {
|
||||
const arr: string[] = multipleSelection.value.map((v) => v.id)
|
||||
if (batchEditDocumentDialogRef) {
|
||||
batchEditDocumentDialogRef?.value?.open(arr)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化轮询
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in New Issue