mirror of
https://github.com/langgenius/dify.git
synced 2026-04-24 09:06:42 +08:00
chore: llm use config
This commit is contained in:
parent
c8ea6d7bfb
commit
291201db1c
@ -1,10 +1,10 @@
|
|||||||
/* eslint-disable react-hooks/exhaustive-deps */
|
|
||||||
import { useCallback, useState } from 'react'
|
import { useCallback, useState } from 'react'
|
||||||
import produce from 'immer'
|
import produce from 'immer'
|
||||||
import type { LLMNodeData, Variable } from '../../types'
|
import type { Variable } from '../../types'
|
||||||
|
import type { LLMNodeType } from './types'
|
||||||
|
|
||||||
const useInput = (initInputs: LLMNodeData) => {
|
const useConfig = (initInputs: LLMNodeType) => {
|
||||||
const [inputs, setInputs] = useState<LLMNodeData>(initInputs)
|
const [inputs, setInputs] = useState<LLMNodeType>(initInputs)
|
||||||
|
|
||||||
// model
|
// model
|
||||||
const handleModelChanged = useCallback((model: { provider: string; modelId: string; mode?: string }) => {
|
const handleModelChanged = useCallback((model: { provider: string; modelId: string; mode?: string }) => {
|
||||||
@ -14,14 +14,14 @@ const useInput = (initInputs: LLMNodeData) => {
|
|||||||
draft.model.mode = model.mode!
|
draft.model.mode = model.mode!
|
||||||
})
|
})
|
||||||
setInputs(newInputs)
|
setInputs(newInputs)
|
||||||
}, [inputs.model])
|
}, [inputs, setInputs])
|
||||||
|
|
||||||
const handleCompletionParamsChange = useCallback((newParams: Record<string, any>) => {
|
const handleCompletionParamsChange = useCallback((newParams: Record<string, any>) => {
|
||||||
const newInputs = produce(inputs, (draft) => {
|
const newInputs = produce(inputs, (draft) => {
|
||||||
draft.model.completion_params = newParams
|
draft.model.completion_params = newParams
|
||||||
})
|
})
|
||||||
setInputs(newInputs)
|
setInputs(newInputs)
|
||||||
}, [inputs.model])
|
}, [inputs, setInputs])
|
||||||
|
|
||||||
// variables
|
// variables
|
||||||
const handleVarListChange = useCallback((newList: Variable[]) => {
|
const handleVarListChange = useCallback((newList: Variable[]) => {
|
||||||
@ -29,7 +29,7 @@ const useInput = (initInputs: LLMNodeData) => {
|
|||||||
draft.variables = newList
|
draft.variables = newList
|
||||||
})
|
})
|
||||||
setInputs(newInputs)
|
setInputs(newInputs)
|
||||||
}, [inputs.variables])
|
}, [inputs, setInputs])
|
||||||
|
|
||||||
const handleAddVariable = useCallback(() => {
|
const handleAddVariable = useCallback(() => {
|
||||||
const newInputs = produce(inputs, (draft) => {
|
const newInputs = produce(inputs, (draft) => {
|
||||||
@ -39,7 +39,7 @@ const useInput = (initInputs: LLMNodeData) => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
setInputs(newInputs)
|
setInputs(newInputs)
|
||||||
}, [inputs.variables])
|
}, [inputs, setInputs])
|
||||||
|
|
||||||
// context
|
// context
|
||||||
const toggleContextEnabled = useCallback(() => {
|
const toggleContextEnabled = useCallback(() => {
|
||||||
@ -47,7 +47,7 @@ const useInput = (initInputs: LLMNodeData) => {
|
|||||||
draft.context.enabled = !draft.context.enabled
|
draft.context.enabled = !draft.context.enabled
|
||||||
})
|
})
|
||||||
setInputs(newInputs)
|
setInputs(newInputs)
|
||||||
}, [inputs.context.enabled])
|
}, [inputs, setInputs])
|
||||||
|
|
||||||
return {
|
return {
|
||||||
inputs,
|
inputs,
|
||||||
@ -59,4 +59,4 @@ const useInput = (initInputs: LLMNodeData) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default useInput
|
export default useConfig
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user