mirror of
https://github.com/langgenius/dify.git
synced 2026-04-28 11:56:55 +08:00
feat: add datasets
This commit is contained in:
parent
045156985a
commit
e4701e26c8
@ -0,0 +1,41 @@
|
|||||||
|
'use client'
|
||||||
|
import { useBoolean } from 'ahooks'
|
||||||
|
import type { FC } from 'react'
|
||||||
|
import React, { useCallback } from 'react'
|
||||||
|
import AddButton from '@/app/components/base/button/add-button'
|
||||||
|
import SelectDataset from '@/app/components/app/configuration/dataset-config/select-dataset'
|
||||||
|
import type { DataSet } from '@/models/datasets'
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
selectedIds: string[]
|
||||||
|
onChange: (dataSets: DataSet[]) => void
|
||||||
|
}
|
||||||
|
|
||||||
|
const AddDataset: FC<Props> = ({
|
||||||
|
selectedIds,
|
||||||
|
onChange,
|
||||||
|
}) => {
|
||||||
|
const [isShowModal, {
|
||||||
|
setTrue: showModal,
|
||||||
|
setFalse: hideModal,
|
||||||
|
}] = useBoolean(false)
|
||||||
|
|
||||||
|
const handleSelect = useCallback((datasets: DataSet[]) => {
|
||||||
|
onChange(datasets)
|
||||||
|
hideModal()
|
||||||
|
}, [onChange, hideModal])
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<AddButton onClick={showModal} />
|
||||||
|
{isShowModal && (
|
||||||
|
<SelectDataset
|
||||||
|
isShow={isShowModal}
|
||||||
|
onClose={hideModal}
|
||||||
|
selectedIds={selectedIds}
|
||||||
|
onSelect={handleSelect}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
export default React.memo(AddDataset)
|
||||||
@ -39,7 +39,6 @@ const RetrievalConfig: FC<Props> = ({
|
|||||||
|
|
||||||
const {
|
const {
|
||||||
defaultModel: rerankDefaultModel,
|
defaultModel: rerankDefaultModel,
|
||||||
currentModel: isRerankDefaultModelVaild,
|
|
||||||
} = useModelListAndDefaultModelAndCurrentProviderAndModel(3)
|
} = useModelListAndDefaultModelAndCurrentProviderAndModel(3)
|
||||||
|
|
||||||
const { multiple_retrieval_config } = payload
|
const { multiple_retrieval_config } = payload
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import VarReferencePicker from '../_base/components/variable/var-reference-picke
|
|||||||
import useConfig from './use-config'
|
import useConfig from './use-config'
|
||||||
import { mockData } from './mock'
|
import { mockData } from './mock'
|
||||||
import RetrievalConfig from './components/retrieval-config'
|
import RetrievalConfig from './components/retrieval-config'
|
||||||
|
import AddKnowledge from './components/add-dataset'
|
||||||
import Field from '@/app/components/workflow/nodes/_base/components/field'
|
import Field from '@/app/components/workflow/nodes/_base/components/field'
|
||||||
import Split from '@/app/components/workflow/nodes/_base/components/split'
|
import Split from '@/app/components/workflow/nodes/_base/components/split'
|
||||||
import OutputVars, { VarItem } from '@/app/components/workflow/nodes/_base/components/output-vars'
|
import OutputVars, { VarItem } from '@/app/components/workflow/nodes/_base/components/output-vars'
|
||||||
@ -18,6 +19,7 @@ const Panel: FC = () => {
|
|||||||
handleQueryVarChange,
|
handleQueryVarChange,
|
||||||
handleRetrievalModeChange,
|
handleRetrievalModeChange,
|
||||||
handleMultipleRetrievalConfigChange,
|
handleMultipleRetrievalConfigChange,
|
||||||
|
handleOnDatasetsChange,
|
||||||
} = useConfig(mockData)
|
} = useConfig(mockData)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -37,7 +39,7 @@ const Panel: FC = () => {
|
|||||||
<Field
|
<Field
|
||||||
title={t(`${i18nPrefix}.knowledge`)}
|
title={t(`${i18nPrefix}.knowledge`)}
|
||||||
operations={
|
operations={
|
||||||
<div className='flex'>
|
<div className='flex items-center space-x-1'>
|
||||||
<RetrievalConfig
|
<RetrievalConfig
|
||||||
payload={{
|
payload={{
|
||||||
retrieval_mode: inputs.retrieval_mode,
|
retrieval_mode: inputs.retrieval_mode,
|
||||||
@ -46,10 +48,15 @@ const Panel: FC = () => {
|
|||||||
onRetrievalModeChange={handleRetrievalModeChange}
|
onRetrievalModeChange={handleRetrievalModeChange}
|
||||||
onMultipleRetrievalConfigChange={handleMultipleRetrievalConfigChange}
|
onMultipleRetrievalConfigChange={handleMultipleRetrievalConfigChange}
|
||||||
/>
|
/>
|
||||||
|
<div className='w-px h-3 bg-gray-200'></div>
|
||||||
|
<AddKnowledge
|
||||||
|
selectedIds={inputs.dataset_ids}
|
||||||
|
onChange={handleOnDatasetsChange}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
|
list
|
||||||
</Field>
|
</Field>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@ -3,10 +3,11 @@ import produce from 'immer'
|
|||||||
import type { ValueSelector } from '../../types'
|
import type { ValueSelector } from '../../types'
|
||||||
import type { KnowledgeRetrievalNodeType, MultipleRetrievalConfig } from './types'
|
import type { KnowledgeRetrievalNodeType, MultipleRetrievalConfig } from './types'
|
||||||
import type { RETRIEVE_TYPE } from '@/types/app'
|
import type { RETRIEVE_TYPE } from '@/types/app'
|
||||||
|
import type { DataSet } from '@/models/datasets'
|
||||||
|
|
||||||
const useConfig = (initInputs: KnowledgeRetrievalNodeType) => {
|
const useConfig = (initInputs: KnowledgeRetrievalNodeType) => {
|
||||||
const [inputs, setInputs] = useState<KnowledgeRetrievalNodeType>(initInputs)
|
const [inputs, setInputs] = useState<KnowledgeRetrievalNodeType>(initInputs)
|
||||||
|
const [selectedDatasets, setSelectedDatasets] = useState<DataSet[]>([])
|
||||||
const handleQueryVarChange = useCallback((newVar: ValueSelector) => {
|
const handleQueryVarChange = useCallback((newVar: ValueSelector) => {
|
||||||
const newInputs = produce(inputs, (draft) => {
|
const newInputs = produce(inputs, (draft) => {
|
||||||
draft.query_variable_selector = newVar
|
draft.query_variable_selector = newVar
|
||||||
@ -28,11 +29,20 @@ const useConfig = (initInputs: KnowledgeRetrievalNodeType) => {
|
|||||||
setInputs(newInputs)
|
setInputs(newInputs)
|
||||||
}, [inputs, setInputs])
|
}, [inputs, setInputs])
|
||||||
|
|
||||||
|
const handleOnDatasetsChange = useCallback((newDatasets: DataSet[]) => {
|
||||||
|
const newInputs = produce(inputs, (draft) => {
|
||||||
|
draft.dataset_ids = newDatasets.map(d => d.id)
|
||||||
|
})
|
||||||
|
setInputs(newInputs)
|
||||||
|
setSelectedDatasets(newDatasets)
|
||||||
|
}, [inputs, setInputs])
|
||||||
|
|
||||||
return {
|
return {
|
||||||
inputs,
|
inputs,
|
||||||
handleQueryVarChange,
|
handleQueryVarChange,
|
||||||
handleRetrievalModeChange,
|
handleRetrievalModeChange,
|
||||||
handleMultipleRetrievalConfigChange,
|
handleMultipleRetrievalConfigChange,
|
||||||
|
handleOnDatasetsChange,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user