mirror of
https://github.com/langgenius/dify.git
synced 2026-05-06 01:26:33 +08:00
feat: params support vison
This commit is contained in:
parent
36ae154ca2
commit
99bf3ff565
@ -16,6 +16,9 @@ const nodeDefault: NodeDefault<ParameterExtractorNodeType> = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
reasoning_mode: ReasoningModeType.prompt,
|
reasoning_mode: ReasoningModeType.prompt,
|
||||||
|
vision: {
|
||||||
|
enabled: false,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
getAvailablePrevNodes(isChatMode: boolean) {
|
getAvailablePrevNodes(isChatMode: boolean) {
|
||||||
const nodes = isChatMode
|
const nodes = isChatMode
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import MemoryConfig from '../_base/components/memory-config'
|
|||||||
import VarReferencePicker from '../_base/components/variable/var-reference-picker'
|
import VarReferencePicker from '../_base/components/variable/var-reference-picker'
|
||||||
import Editor from '../_base/components/prompt/editor'
|
import Editor from '../_base/components/prompt/editor'
|
||||||
import ResultPanel from '../../run/result-panel'
|
import ResultPanel from '../../run/result-panel'
|
||||||
|
import ConfigVision from '../_base/components/config-vision'
|
||||||
import useConfig from './use-config'
|
import useConfig from './use-config'
|
||||||
import type { ParameterExtractorNodeType } from './types'
|
import type { ParameterExtractorNodeType } from './types'
|
||||||
import ExtractParameter from './components/extract-parameter/list'
|
import ExtractParameter from './components/extract-parameter/list'
|
||||||
@ -54,6 +55,9 @@ const Panel: FC<NodePanelProps<ParameterExtractorNodeType>> = ({
|
|||||||
availableNodesWithParent,
|
availableNodesWithParent,
|
||||||
inputVarValues,
|
inputVarValues,
|
||||||
varInputs,
|
varInputs,
|
||||||
|
isVisionModel,
|
||||||
|
handleVisionResolutionChange,
|
||||||
|
handleVisionResolutionEnabledChange,
|
||||||
isShowSingleRun,
|
isShowSingleRun,
|
||||||
hideSingleRun,
|
hideSingleRun,
|
||||||
runningStatus,
|
runningStatus,
|
||||||
@ -68,20 +72,6 @@ const Panel: FC<NodePanelProps<ParameterExtractorNodeType>> = ({
|
|||||||
return (
|
return (
|
||||||
<div className='mt-2'>
|
<div className='mt-2'>
|
||||||
<div className='px-4 pb-4 space-y-4'>
|
<div className='px-4 pb-4 space-y-4'>
|
||||||
<Field
|
|
||||||
title={t(`${i18nPrefix}.inputVar`)}
|
|
||||||
>
|
|
||||||
<>
|
|
||||||
<VarReferencePicker
|
|
||||||
readonly={readOnly}
|
|
||||||
nodeId={id}
|
|
||||||
isShowNodeName
|
|
||||||
value={inputs.query || []}
|
|
||||||
onChange={handleInputVarChange}
|
|
||||||
filterVar={filterVar}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
</Field>
|
|
||||||
<Field
|
<Field
|
||||||
title={t(`${i18nCommonPrefix}.model`)}
|
title={t(`${i18nCommonPrefix}.model`)}
|
||||||
>
|
>
|
||||||
@ -100,6 +90,30 @@ const Panel: FC<NodePanelProps<ParameterExtractorNodeType>> = ({
|
|||||||
readonly={readOnly}
|
readonly={readOnly}
|
||||||
/>
|
/>
|
||||||
</Field>
|
</Field>
|
||||||
|
<Field
|
||||||
|
title={t(`${i18nPrefix}.inputVar`)}
|
||||||
|
>
|
||||||
|
<>
|
||||||
|
<VarReferencePicker
|
||||||
|
readonly={readOnly}
|
||||||
|
nodeId={id}
|
||||||
|
isShowNodeName
|
||||||
|
value={inputs.query || []}
|
||||||
|
onChange={handleInputVarChange}
|
||||||
|
filterVar={filterVar}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
</Field>
|
||||||
|
<Split />
|
||||||
|
<ConfigVision
|
||||||
|
nodeId={id}
|
||||||
|
readOnly={readOnly}
|
||||||
|
isVisionModel={isVisionModel}
|
||||||
|
enabled={inputs.vision.enabled}
|
||||||
|
onEnabledChange={handleVisionResolutionEnabledChange}
|
||||||
|
config={inputs.vision.configs}
|
||||||
|
onConfigChange={handleVisionResolutionChange}
|
||||||
|
/>
|
||||||
<Field
|
<Field
|
||||||
title={t(`${i18nPrefix}.extractParameters`)}
|
title={t(`${i18nPrefix}.extractParameters`)}
|
||||||
operations={
|
operations={
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import type { CommonNodeType, Memory, ModelConfig, ValueSelector } from '@/app/components/workflow/types'
|
import type { CommonNodeType, Memory, ModelConfig, ValueSelector, VisionSetting } from '@/app/components/workflow/types'
|
||||||
|
|
||||||
export enum ParamType {
|
export enum ParamType {
|
||||||
string = 'string',
|
string = 'string',
|
||||||
@ -30,4 +30,8 @@ export type ParameterExtractorNodeType = CommonNodeType & {
|
|||||||
parameters: Param[]
|
parameters: Param[]
|
||||||
instruction: string
|
instruction: string
|
||||||
memory?: Memory
|
memory?: Memory
|
||||||
|
vision: {
|
||||||
|
enabled: boolean
|
||||||
|
configs?: VisionSetting
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import {
|
|||||||
useWorkflow,
|
useWorkflow,
|
||||||
} from '../../hooks'
|
} from '../../hooks'
|
||||||
import useOneStepRun from '../_base/hooks/use-one-step-run'
|
import useOneStepRun from '../_base/hooks/use-one-step-run'
|
||||||
|
import useConfigVision from '../../hooks/use-config-vision'
|
||||||
import type { Param, ParameterExtractorNodeType, ReasoningModeType } from './types'
|
import type { Param, ParameterExtractorNodeType, ReasoningModeType } from './types'
|
||||||
import { useModelListAndDefaultModelAndCurrentProviderAndModel, useTextGenerationCurrentProviderAndModelAndModelList } from '@/app/components/header/account-setting/model-provider-page/hooks'
|
import { useModelListAndDefaultModelAndCurrentProviderAndModel, useTextGenerationCurrentProviderAndModelAndModelList } from '@/app/components/header/account-setting/model-provider-page/hooks'
|
||||||
import {
|
import {
|
||||||
@ -84,9 +85,23 @@ const useConfig = (id: string, payload: ParameterExtractorNodeType) => {
|
|||||||
}
|
}
|
||||||
const modelMode = inputs.model?.mode
|
const modelMode = inputs.model?.mode
|
||||||
const isChatModel = modelMode === 'chat'
|
const isChatModel = modelMode === 'chat'
|
||||||
|
|
||||||
const isCompletionModel = !isChatModel
|
const isCompletionModel = !isChatModel
|
||||||
|
|
||||||
|
const {
|
||||||
|
isVisionModel,
|
||||||
|
handleVisionResolutionEnabledChange,
|
||||||
|
handleVisionResolutionChange,
|
||||||
|
handleModelChanged: handleVisionConfigAfterModelChanged,
|
||||||
|
} = useConfigVision(model, {
|
||||||
|
payload: inputs.vision,
|
||||||
|
onChange: (newPayload) => {
|
||||||
|
const newInputs = produce(inputs, (draft) => {
|
||||||
|
draft.vision = newPayload
|
||||||
|
})
|
||||||
|
setInputs(newInputs)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
const appendDefaultPromptConfig = useCallback((draft: ParameterExtractorNodeType, defaultConfig: any, _passInIsChatMode?: boolean) => {
|
const appendDefaultPromptConfig = useCallback((draft: ParameterExtractorNodeType, defaultConfig: any, _passInIsChatMode?: boolean) => {
|
||||||
const promptTemplates = defaultConfig.prompt_templates
|
const promptTemplates = defaultConfig.prompt_templates
|
||||||
if (!isChatModel) {
|
if (!isChatModel) {
|
||||||
@ -97,7 +112,7 @@ const useConfig = (id: string, payload: ParameterExtractorNodeType) => {
|
|||||||
}
|
}
|
||||||
}, [isChatModel])
|
}, [isChatModel])
|
||||||
|
|
||||||
// const [modelChanged, setModelChanged] = useState(false)
|
const [modelChanged, setModelChanged] = useState(false)
|
||||||
const {
|
const {
|
||||||
currentProvider,
|
currentProvider,
|
||||||
currentModel,
|
currentModel,
|
||||||
@ -113,7 +128,7 @@ const useConfig = (id: string, payload: ParameterExtractorNodeType) => {
|
|||||||
appendDefaultPromptConfig(draft, defaultConfig, model.mode === 'chat')
|
appendDefaultPromptConfig(draft, defaultConfig, model.mode === 'chat')
|
||||||
})
|
})
|
||||||
setInputs(newInputs)
|
setInputs(newInputs)
|
||||||
// setModelChanged(true)
|
setModelChanged(true)
|
||||||
}, [setInputs, defaultConfig, appendDefaultPromptConfig])
|
}, [setInputs, defaultConfig, appendDefaultPromptConfig])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -126,6 +141,15 @@ const useConfig = (id: string, payload: ParameterExtractorNodeType) => {
|
|||||||
}
|
}
|
||||||
}, [model?.provider, currentProvider, currentModel, handleModelChanged])
|
}, [model?.provider, currentProvider, currentModel, handleModelChanged])
|
||||||
|
|
||||||
|
// change to vision model to set vision enabled, else disabled
|
||||||
|
useEffect(() => {
|
||||||
|
if (!modelChanged)
|
||||||
|
return
|
||||||
|
setModelChanged(false)
|
||||||
|
handleVisionConfigAfterModelChanged()
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [isVisionModel, modelChanged])
|
||||||
|
|
||||||
const {
|
const {
|
||||||
currentModel: currModel,
|
currentModel: currModel,
|
||||||
} = useTextGenerationCurrentProviderAndModelAndModelList(
|
} = useTextGenerationCurrentProviderAndModelAndModelList(
|
||||||
@ -245,6 +269,9 @@ const useConfig = (id: string, payload: ParameterExtractorNodeType) => {
|
|||||||
handleMemoryChange,
|
handleMemoryChange,
|
||||||
varInputs,
|
varInputs,
|
||||||
inputVarValues,
|
inputVarValues,
|
||||||
|
isVisionModel,
|
||||||
|
handleVisionResolutionEnabledChange,
|
||||||
|
handleVisionResolutionChange,
|
||||||
isShowSingleRun,
|
isShowSingleRun,
|
||||||
hideSingleRun,
|
hideSingleRun,
|
||||||
runningStatus,
|
runningStatus,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user