mirror of
https://github.com/langgenius/dify.git
synced 2026-04-28 03:36:36 +08:00
Co-authored-by: liuchen15 <liuchen15@gaotu.cn>
This commit is contained in:
parent
c71f7c7613
commit
b7360140ee
@ -27,6 +27,9 @@ const useConfig = (id: string, payload: LLMNodeType) => {
|
|||||||
const [defaultRolePrefix, setDefaultRolePrefix] = useState<{ user: string; assistant: string }>({ user: '', assistant: '' })
|
const [defaultRolePrefix, setDefaultRolePrefix] = useState<{ user: string; assistant: string }>({ user: '', assistant: '' })
|
||||||
const { inputs, setInputs: doSetInputs } = useNodeCrud<LLMNodeType>(id, payload)
|
const { inputs, setInputs: doSetInputs } = useNodeCrud<LLMNodeType>(id, payload)
|
||||||
const inputRef = useRef(inputs)
|
const inputRef = useRef(inputs)
|
||||||
|
useEffect(() => {
|
||||||
|
inputRef.current = inputs
|
||||||
|
}, [inputs])
|
||||||
|
|
||||||
const { deleteNodeInspectorVars } = useInspectVarsCrud()
|
const { deleteNodeInspectorVars } = useInspectVarsCrud()
|
||||||
|
|
||||||
@ -117,7 +120,7 @@ const useConfig = (id: string, payload: LLMNodeType) => {
|
|||||||
} = useConfigVision(model, {
|
} = useConfigVision(model, {
|
||||||
payload: inputs.vision,
|
payload: inputs.vision,
|
||||||
onChange: (newPayload) => {
|
onChange: (newPayload) => {
|
||||||
const newInputs = produce(inputs, (draft) => {
|
const newInputs = produce(inputRef.current, (draft) => {
|
||||||
draft.vision = newPayload
|
draft.vision = newPayload
|
||||||
})
|
})
|
||||||
setInputs(newInputs)
|
setInputs(newInputs)
|
||||||
@ -148,11 +151,11 @@ const useConfig = (id: string, payload: LLMNodeType) => {
|
|||||||
}, [model.provider, currentProvider, currentModel, handleModelChanged])
|
}, [model.provider, currentProvider, currentModel, handleModelChanged])
|
||||||
|
|
||||||
const handleCompletionParamsChange = useCallback((newParams: Record<string, any>) => {
|
const handleCompletionParamsChange = useCallback((newParams: Record<string, any>) => {
|
||||||
const newInputs = produce(inputs, (draft) => {
|
const newInputs = produce(inputRef.current, (draft) => {
|
||||||
draft.model.completion_params = newParams
|
draft.model.completion_params = newParams
|
||||||
})
|
})
|
||||||
setInputs(newInputs)
|
setInputs(newInputs)
|
||||||
}, [inputs, setInputs])
|
}, [setInputs])
|
||||||
|
|
||||||
// change to vision model to set vision enabled, else disabled
|
// change to vision model to set vision enabled, else disabled
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -238,29 +241,29 @@ const useConfig = (id: string, payload: LLMNodeType) => {
|
|||||||
|
|
||||||
// context
|
// context
|
||||||
const handleContextVarChange = useCallback((newVar: ValueSelector | string) => {
|
const handleContextVarChange = useCallback((newVar: ValueSelector | string) => {
|
||||||
const newInputs = produce(inputs, (draft) => {
|
const newInputs = produce(inputRef.current, (draft) => {
|
||||||
draft.context.variable_selector = newVar as ValueSelector || []
|
draft.context.variable_selector = newVar as ValueSelector || []
|
||||||
draft.context.enabled = !!(newVar && newVar.length > 0)
|
draft.context.enabled = !!(newVar && newVar.length > 0)
|
||||||
})
|
})
|
||||||
setInputs(newInputs)
|
setInputs(newInputs)
|
||||||
}, [inputs, setInputs])
|
}, [setInputs])
|
||||||
|
|
||||||
const handlePromptChange = useCallback((newPrompt: PromptItem[] | PromptItem) => {
|
const handlePromptChange = useCallback((newPrompt: PromptItem[] | PromptItem) => {
|
||||||
const newInputs = produce(inputRef.current, (draft) => {
|
const newInputs = produce(inputRef.current, (draft) => {
|
||||||
draft.prompt_template = newPrompt
|
draft.prompt_template = newPrompt
|
||||||
})
|
})
|
||||||
setInputs(newInputs)
|
setInputs(newInputs)
|
||||||
}, [inputs, setInputs])
|
}, [setInputs])
|
||||||
|
|
||||||
const handleMemoryChange = useCallback((newMemory?: Memory) => {
|
const handleMemoryChange = useCallback((newMemory?: Memory) => {
|
||||||
const newInputs = produce(inputs, (draft) => {
|
const newInputs = produce(inputRef.current, (draft) => {
|
||||||
draft.memory = newMemory
|
draft.memory = newMemory
|
||||||
})
|
})
|
||||||
setInputs(newInputs)
|
setInputs(newInputs)
|
||||||
}, [inputs, setInputs])
|
}, [setInputs])
|
||||||
|
|
||||||
const handleSyeQueryChange = useCallback((newQuery: string) => {
|
const handleSyeQueryChange = useCallback((newQuery: string) => {
|
||||||
const newInputs = produce(inputs, (draft) => {
|
const newInputs = produce(inputRef.current, (draft) => {
|
||||||
if (!draft.memory) {
|
if (!draft.memory) {
|
||||||
draft.memory = {
|
draft.memory = {
|
||||||
window: {
|
window: {
|
||||||
@ -275,7 +278,7 @@ const useConfig = (id: string, payload: LLMNodeType) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
setInputs(newInputs)
|
setInputs(newInputs)
|
||||||
}, [inputs, setInputs])
|
}, [setInputs])
|
||||||
|
|
||||||
// structure output
|
// structure output
|
||||||
const { data: modelList } = useModelList(ModelTypeEnum.textGeneration)
|
const { data: modelList } = useModelList(ModelTypeEnum.textGeneration)
|
||||||
@ -286,22 +289,22 @@ const useConfig = (id: string, payload: LLMNodeType) => {
|
|||||||
|
|
||||||
const [structuredOutputCollapsed, setStructuredOutputCollapsed] = useState(true)
|
const [structuredOutputCollapsed, setStructuredOutputCollapsed] = useState(true)
|
||||||
const handleStructureOutputEnableChange = useCallback((enabled: boolean) => {
|
const handleStructureOutputEnableChange = useCallback((enabled: boolean) => {
|
||||||
const newInputs = produce(inputs, (draft) => {
|
const newInputs = produce(inputRef.current, (draft) => {
|
||||||
draft.structured_output_enabled = enabled
|
draft.structured_output_enabled = enabled
|
||||||
})
|
})
|
||||||
setInputs(newInputs)
|
setInputs(newInputs)
|
||||||
if (enabled)
|
if (enabled)
|
||||||
setStructuredOutputCollapsed(false)
|
setStructuredOutputCollapsed(false)
|
||||||
deleteNodeInspectorVars(id)
|
deleteNodeInspectorVars(id)
|
||||||
}, [inputs, setInputs, deleteNodeInspectorVars, id])
|
}, [setInputs, deleteNodeInspectorVars, id])
|
||||||
|
|
||||||
const handleStructureOutputChange = useCallback((newOutput: StructuredOutput) => {
|
const handleStructureOutputChange = useCallback((newOutput: StructuredOutput) => {
|
||||||
const newInputs = produce(inputs, (draft) => {
|
const newInputs = produce(inputRef.current, (draft) => {
|
||||||
draft.structured_output = newOutput
|
draft.structured_output = newOutput
|
||||||
})
|
})
|
||||||
setInputs(newInputs)
|
setInputs(newInputs)
|
||||||
deleteNodeInspectorVars(id)
|
deleteNodeInspectorVars(id)
|
||||||
}, [inputs, setInputs, deleteNodeInspectorVars, id])
|
}, [setInputs, deleteNodeInspectorVars, id])
|
||||||
|
|
||||||
const filterInputVar = useCallback((varPayload: Var) => {
|
const filterInputVar = useCallback((varPayload: Var) => {
|
||||||
return [VarType.number, VarType.string, VarType.secret, VarType.arrayString, VarType.arrayNumber, VarType.file, VarType.arrayFile].includes(varPayload.type)
|
return [VarType.number, VarType.string, VarType.secret, VarType.arrayString, VarType.arrayNumber, VarType.file, VarType.arrayFile].includes(varPayload.type)
|
||||||
@ -317,11 +320,11 @@ const useConfig = (id: string, payload: LLMNodeType) => {
|
|||||||
|
|
||||||
// reasoning format
|
// reasoning format
|
||||||
const handleReasoningFormatChange = useCallback((reasoningFormat: 'tagged' | 'separated') => {
|
const handleReasoningFormatChange = useCallback((reasoningFormat: 'tagged' | 'separated') => {
|
||||||
const newInputs = produce(inputs, (draft) => {
|
const newInputs = produce(inputRef.current, (draft) => {
|
||||||
draft.reasoning_format = reasoningFormat
|
draft.reasoning_format = reasoningFormat
|
||||||
})
|
})
|
||||||
setInputs(newInputs)
|
setInputs(newInputs)
|
||||||
}, [inputs, setInputs])
|
}, [setInputs])
|
||||||
|
|
||||||
const {
|
const {
|
||||||
availableVars,
|
availableVars,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user