mirror of
https://github.com/langgenius/dify.git
synced 2026-04-29 12:37:20 +08:00
feat: knowledge node var init value and limit
This commit is contained in:
parent
4835358f24
commit
aff5ab933b
@ -16,7 +16,7 @@ export const useNodesInitialData = () => {
|
|||||||
return useMemo(() => produce(NODES_INITIAL_DATA, (draft) => {
|
return useMemo(() => produce(NODES_INITIAL_DATA, (draft) => {
|
||||||
Object.keys(draft).forEach((key) => {
|
Object.keys(draft).forEach((key) => {
|
||||||
draft[key as BlockEnum].title = t(`workflow.blocks.${key}`)
|
draft[key as BlockEnum].title = t(`workflow.blocks.${key}`)
|
||||||
|
draft[key as BlockEnum]._isReady = true
|
||||||
if (nodesDefaultConfigs[key as BlockEnum]) {
|
if (nodesDefaultConfigs[key as BlockEnum]) {
|
||||||
draft[key as BlockEnum] = {
|
draft[key as BlockEnum] = {
|
||||||
...draft[key as BlockEnum],
|
...draft[key as BlockEnum],
|
||||||
|
|||||||
@ -26,6 +26,7 @@ const Panel: FC<NodePanelProps<KnowledgeRetrievalNodeType>> = ({
|
|||||||
const {
|
const {
|
||||||
inputs,
|
inputs,
|
||||||
handleQueryVarChange,
|
handleQueryVarChange,
|
||||||
|
filterVar,
|
||||||
handleRetrievalModeChange,
|
handleRetrievalModeChange,
|
||||||
handleMultipleRetrievalConfigChange,
|
handleMultipleRetrievalConfigChange,
|
||||||
selectedDatasets,
|
selectedDatasets,
|
||||||
@ -52,6 +53,8 @@ const Panel: FC<NodePanelProps<KnowledgeRetrievalNodeType>> = ({
|
|||||||
isShowNodeName
|
isShowNodeName
|
||||||
value={inputs.query_variable_selector}
|
value={inputs.query_variable_selector}
|
||||||
onChange={handleQueryVarChange}
|
onChange={handleQueryVarChange}
|
||||||
|
filterVar={filterVar}
|
||||||
|
width={370}
|
||||||
/>
|
/>
|
||||||
</Field>
|
</Field>
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
import { useCallback, useEffect, useState } from 'react'
|
import { useCallback, useEffect, useState } from 'react'
|
||||||
import produce from 'immer'
|
import produce from 'immer'
|
||||||
import type { ValueSelector } from '../../types'
|
import type { ValueSelector, Var } from '../../types'
|
||||||
|
import { BlockEnum, VarType } from '../../types'
|
||||||
|
import { useIsChatMode, useWorkflow } from '../../hooks'
|
||||||
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'
|
import type { DataSet } from '@/models/datasets'
|
||||||
@ -9,10 +11,14 @@ import useNodeCrud from '@/app/components/workflow/nodes/_base/hooks/use-node-cr
|
|||||||
import useOneStepRun from '@/app/components/workflow/nodes/_base/hooks/use-one-step-run'
|
import useOneStepRun from '@/app/components/workflow/nodes/_base/hooks/use-one-step-run'
|
||||||
|
|
||||||
const useConfig = (id: string, payload: KnowledgeRetrievalNodeType) => {
|
const useConfig = (id: string, payload: KnowledgeRetrievalNodeType) => {
|
||||||
|
const isChatMode = useIsChatMode()
|
||||||
|
const { getBeforeNodesInSameBranch } = useWorkflow()
|
||||||
|
const startNode = getBeforeNodesInSameBranch(id).find(node => node.data.type === BlockEnum.Start)
|
||||||
|
const startNodeId = startNode?.id
|
||||||
const { inputs, setInputs } = useNodeCrud<KnowledgeRetrievalNodeType>(id, payload)
|
const { inputs, setInputs } = useNodeCrud<KnowledgeRetrievalNodeType>(id, payload)
|
||||||
const handleQueryVarChange = useCallback((newVar: ValueSelector) => {
|
const handleQueryVarChange = useCallback((newVar: ValueSelector | string) => {
|
||||||
const newInputs = produce(inputs, (draft) => {
|
const newInputs = produce(inputs, (draft) => {
|
||||||
draft.query_variable_selector = newVar
|
draft.query_variable_selector = newVar as ValueSelector
|
||||||
})
|
})
|
||||||
setInputs(newInputs)
|
setInputs(newInputs)
|
||||||
}, [inputs, setInputs])
|
}, [inputs, setInputs])
|
||||||
@ -45,8 +51,19 @@ const useConfig = (id: string, payload: KnowledgeRetrievalNodeType) => {
|
|||||||
})
|
})
|
||||||
setInputs(newInputs)
|
setInputs(newInputs)
|
||||||
})()
|
})()
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (inputs._isReady) {
|
||||||
|
if (isChatMode && inputs.query_variable_selector.length === 0 && startNodeId) {
|
||||||
|
handleQueryVarChange(
|
||||||
|
[startNodeId, 'sys.query'],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [inputs._isReady])
|
||||||
|
|
||||||
const handleOnDatasetsChange = useCallback((newDatasets: DataSet[]) => {
|
const handleOnDatasetsChange = useCallback((newDatasets: DataSet[]) => {
|
||||||
const newInputs = produce(inputs, (draft) => {
|
const newInputs = produce(inputs, (draft) => {
|
||||||
draft.dataset_ids = newDatasets.map(d => d.id)
|
draft.dataset_ids = newDatasets.map(d => d.id)
|
||||||
@ -55,6 +72,10 @@ const useConfig = (id: string, payload: KnowledgeRetrievalNodeType) => {
|
|||||||
setSelectedDatasets(newDatasets)
|
setSelectedDatasets(newDatasets)
|
||||||
}, [inputs, setInputs])
|
}, [inputs, setInputs])
|
||||||
|
|
||||||
|
const filterVar = useCallback((varPayload: Var) => {
|
||||||
|
return varPayload.type === VarType.string
|
||||||
|
}, [])
|
||||||
|
|
||||||
// single run
|
// single run
|
||||||
const {
|
const {
|
||||||
isShowSingleRun,
|
isShowSingleRun,
|
||||||
@ -84,6 +105,7 @@ const useConfig = (id: string, payload: KnowledgeRetrievalNodeType) => {
|
|||||||
return {
|
return {
|
||||||
inputs,
|
inputs,
|
||||||
handleQueryVarChange,
|
handleQueryVarChange,
|
||||||
|
filterVar,
|
||||||
handleRetrievalModeChange,
|
handleRetrievalModeChange,
|
||||||
handleMultipleRetrievalConfigChange,
|
handleMultipleRetrievalConfigChange,
|
||||||
selectedDatasets,
|
selectedDatasets,
|
||||||
|
|||||||
@ -33,6 +33,7 @@ export type CommonNodeType<T = {}> = {
|
|||||||
_isSingleRun?: boolean
|
_isSingleRun?: boolean
|
||||||
_runningStatus?: NodeRunningStatus
|
_runningStatus?: NodeRunningStatus
|
||||||
_singleRunningStatus?: NodeRunningStatus
|
_singleRunningStatus?: NodeRunningStatus
|
||||||
|
_isReady?: boolean
|
||||||
selected?: boolean
|
selected?: boolean
|
||||||
title: string
|
title: string
|
||||||
desc: string
|
desc: string
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user