mirror of https://github.com/langgenius/dify.git
refactor: dataset creation to support pipeline datasets, update related types and hooks
This commit is contained in:
parent
7ce9710229
commit
c240cf3bb1
|
|
@ -8,12 +8,12 @@ import type { AppIconType } from '@/types/app'
|
|||
import { RiCloseLine } from '@remixicon/react'
|
||||
import PermissionSelector from '../../settings/permission-selector'
|
||||
import type { CreateDatasetReq } from '@/models/datasets'
|
||||
import { DatasetPermission } from '@/models/datasets'
|
||||
import { ChunkingMode, DatasetPermission } from '@/models/datasets'
|
||||
import { useMembers } from '@/service/use-common'
|
||||
import Button from '@/app/components/base/button'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import Toast from '@/app/components/base/toast'
|
||||
import { useCreateDataset } from '@/service/knowledge/use-create-dataset'
|
||||
import { useCreatePipelineDataset } from '@/service/knowledge/use-create-dataset'
|
||||
import type { Member } from '@/models/common'
|
||||
|
||||
type CreateFromScratchProps = {
|
||||
|
|
@ -75,7 +75,7 @@ const CreateFromScratch = ({
|
|||
setPermission(value!)
|
||||
}, [])
|
||||
|
||||
const { mutateAsync: createEmptyDataset } = useCreateDataset()
|
||||
const { mutateAsync: createEmptyDataset } = useCreatePipelineDataset()
|
||||
|
||||
const handleCreate = useCallback(async () => {
|
||||
if (!name) {
|
||||
|
|
@ -94,6 +94,7 @@ const CreateFromScratch = ({
|
|||
icon_background: appIcon.type === 'image' ? undefined : appIcon.background,
|
||||
icon_url: appIcon.type === 'image' ? appIcon.url : undefined,
|
||||
},
|
||||
doc_form: ChunkingMode.text,
|
||||
permission,
|
||||
}
|
||||
// Handle permission
|
||||
|
|
|
|||
|
|
@ -51,6 +51,12 @@ const DatasetCard = ({
|
|||
return dataset.provider === EXTERNAL_PROVIDER
|
||||
}, [dataset.provider])
|
||||
const Icon = isExternalProvider ? DOC_FORM_ICON.external : (DOC_FORM_ICON[dataset.doc_form] || General)
|
||||
const iconInfo = dataset.icon_info || {
|
||||
icon: '📙',
|
||||
icon_type: 'emoji',
|
||||
icon_background: '#FFF4ED',
|
||||
icon_url: '',
|
||||
}
|
||||
const { formatIndexingTechniqueAndMethod } = useKnowledge()
|
||||
const documentCount = useMemo(() => {
|
||||
const availableDocCount = dataset.available_document_count || dataset.document_count
|
||||
|
|
@ -122,16 +128,23 @@ const DatasetCard = ({
|
|||
<div className={cn('flex items-center gap-x-3 px-4 pb-2 pt-4', !dataset.embedding_available && 'opacity-30')}>
|
||||
<div className='relative shrink-0'>
|
||||
<AppIcon
|
||||
iconType='emoji'
|
||||
icon='📙'
|
||||
size='large'
|
||||
iconType={iconInfo.icon_type}
|
||||
icon={iconInfo.icon}
|
||||
background={iconInfo.icon_type === 'image' ? undefined : iconInfo.icon_background}
|
||||
imageUrl={iconInfo.icon_type === 'image' ? iconInfo.icon_url : undefined}
|
||||
/>
|
||||
<div className='absolute -bottom-1 -right-1 z-10'>
|
||||
<Icon className='size-4' />
|
||||
</div>
|
||||
</div>
|
||||
<div className='flex grow flex-col gap-y-1 py-px'>
|
||||
<div className='system-md-semibold truncate text-text-secondary' title={dataset.name}>{dataset.name}</div>
|
||||
<div className='flex grow flex-col gap-y-1 overflow-hidden py-px'>
|
||||
<div
|
||||
className='system-md-semibold truncate text-text-secondary'
|
||||
title={dataset.name}
|
||||
>
|
||||
{dataset.name}
|
||||
</div>
|
||||
<div className='system-2xs-medium-uppercase flex items-center gap-x-3 text-text-tertiary'>
|
||||
{!isExternalProvider ? (
|
||||
<>
|
||||
|
|
|
|||
|
|
@ -729,10 +729,6 @@ export type CreateDatasetReq = {
|
|||
user_id: string
|
||||
role?: 'owner' | 'admin' | 'editor' | 'normal' | 'dataset_operator'
|
||||
}[]
|
||||
indexing_technique?: IndexingType
|
||||
retrieval_mode?: RetrievalConfig
|
||||
embedding_model?: string
|
||||
embedding_model_provider?: string
|
||||
}
|
||||
|
||||
export type CreateDatasetResponse = {
|
||||
|
|
@ -740,7 +736,6 @@ export type CreateDatasetResponse = {
|
|||
name: string
|
||||
description: string
|
||||
permission: DatasetPermission
|
||||
data_source_type: DataSourceType
|
||||
indexing_technique: IndexingType
|
||||
created_by: string
|
||||
created_at: number
|
||||
|
|
|
|||
|
|
@ -240,13 +240,13 @@ export const useFetchDefaultProcessRule = (
|
|||
})
|
||||
}
|
||||
|
||||
export const useCreateDataset = (
|
||||
export const useCreatePipelineDataset = (
|
||||
mutationOptions: MutationOptions<CreateDatasetResponse, Error, CreateDatasetReq> = {},
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationKey: [NAME_SPACE, 'create-dataset'],
|
||||
mutationKey: [NAME_SPACE, 'create-pipeline-empty-dataset'],
|
||||
mutationFn: (req: CreateDatasetReq) => {
|
||||
return post<CreateDatasetResponse>('/datasets', { body: req })
|
||||
return post<CreateDatasetResponse>('/rag/pipeline/empty-dataset', { body: req })
|
||||
},
|
||||
...mutationOptions,
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue