mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-20 12:29:17 +08:00
feat: classify support vision
This commit is contained in:
parent
ef93d60534
commit
36ae154ca2
@ -17,7 +17,9 @@ type Params = {
|
|||||||
onChange: (payload: Payload) => void
|
onChange: (payload: Payload) => void
|
||||||
}
|
}
|
||||||
const useConfigVision = (model: ModelConfig, {
|
const useConfigVision = (model: ModelConfig, {
|
||||||
payload,
|
payload = {
|
||||||
|
enabled: false,
|
||||||
|
},
|
||||||
onChange,
|
onChange,
|
||||||
}: Params) => {
|
}: Params) => {
|
||||||
const {
|
const {
|
||||||
|
@ -26,6 +26,9 @@ const nodeDefault: NodeDefault<QuestionClassifierNodeType> = {
|
|||||||
name: '',
|
name: '',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
vision: {
|
||||||
|
enabled: false,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
getAvailablePrevNodes(isChatMode: boolean) {
|
getAvailablePrevNodes(isChatMode: boolean) {
|
||||||
const nodes = isChatMode
|
const nodes = isChatMode
|
||||||
|
@ -2,6 +2,7 @@ import type { FC } from 'react'
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import VarReferencePicker from '../_base/components/variable/var-reference-picker'
|
import VarReferencePicker from '../_base/components/variable/var-reference-picker'
|
||||||
|
import ConfigVision from '../_base/components/config-vision'
|
||||||
import useConfig from './use-config'
|
import useConfig from './use-config'
|
||||||
import ClassList from './components/class-list'
|
import ClassList from './components/class-list'
|
||||||
import AdvancedSetting from './components/advanced-setting'
|
import AdvancedSetting from './components/advanced-setting'
|
||||||
@ -39,6 +40,9 @@ const Panel: FC<NodePanelProps<QuestionClassifierNodeType>> = ({
|
|||||||
varInputs,
|
varInputs,
|
||||||
setInputVarValues,
|
setInputVarValues,
|
||||||
handleMemoryChange,
|
handleMemoryChange,
|
||||||
|
isVisionModel,
|
||||||
|
handleVisionResolutionChange,
|
||||||
|
handleVisionResolutionEnabledChange,
|
||||||
isShowSingleRun,
|
isShowSingleRun,
|
||||||
hideSingleRun,
|
hideSingleRun,
|
||||||
runningStatus,
|
runningStatus,
|
||||||
@ -53,18 +57,6 @@ const Panel: FC<NodePanelProps<QuestionClassifierNodeType>> = ({
|
|||||||
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}.inputVars`)}
|
|
||||||
>
|
|
||||||
<VarReferencePicker
|
|
||||||
readonly={readOnly}
|
|
||||||
isShowNodeName
|
|
||||||
nodeId={id}
|
|
||||||
value={inputs.query_variable_selector}
|
|
||||||
onChange={handleQueryVarChange}
|
|
||||||
filterVar={filterVar}
|
|
||||||
/>
|
|
||||||
</Field>
|
|
||||||
<Field
|
<Field
|
||||||
title={t(`${i18nPrefix}.model`)}
|
title={t(`${i18nPrefix}.model`)}
|
||||||
>
|
>
|
||||||
@ -83,6 +75,28 @@ const Panel: FC<NodePanelProps<QuestionClassifierNodeType>> = ({
|
|||||||
readonly={readOnly}
|
readonly={readOnly}
|
||||||
/>
|
/>
|
||||||
</Field>
|
</Field>
|
||||||
|
<Field
|
||||||
|
title={t(`${i18nPrefix}.inputVars`)}
|
||||||
|
>
|
||||||
|
<VarReferencePicker
|
||||||
|
readonly={readOnly}
|
||||||
|
isShowNodeName
|
||||||
|
nodeId={id}
|
||||||
|
value={inputs.query_variable_selector}
|
||||||
|
onChange={handleQueryVarChange}
|
||||||
|
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}.class`)}
|
title={t(`${i18nPrefix}.class`)}
|
||||||
>
|
>
|
||||||
|
@ -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 type Topic = {
|
export type Topic = {
|
||||||
id: string
|
id: string
|
||||||
@ -11,4 +11,8 @@ export type QuestionClassifierNodeType = CommonNodeType & {
|
|||||||
classes: Topic[]
|
classes: Topic[]
|
||||||
instruction: string
|
instruction: string
|
||||||
memory?: Memory
|
memory?: Memory
|
||||||
|
vision: {
|
||||||
|
enabled: boolean
|
||||||
|
configs?: VisionSetting
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { useCallback, useEffect, useRef } from 'react'
|
import { useCallback, useEffect, useRef, useState } from 'react'
|
||||||
import produce from 'immer'
|
import produce from 'immer'
|
||||||
import { BlockEnum, VarType } from '../../types'
|
import { BlockEnum, VarType } from '../../types'
|
||||||
import type { Memory, ValueSelector, Var } from '../../types'
|
import type { Memory, ValueSelector, Var } from '../../types'
|
||||||
@ -8,6 +8,7 @@ import {
|
|||||||
} from '../../hooks'
|
} from '../../hooks'
|
||||||
import { useStore } from '../../store'
|
import { useStore } from '../../store'
|
||||||
import useAvailableVarList from '../_base/hooks/use-available-var-list'
|
import useAvailableVarList from '../_base/hooks/use-available-var-list'
|
||||||
|
import useConfigVision from '../../hooks/use-config-vision'
|
||||||
import type { QuestionClassifierNodeType } from './types'
|
import type { QuestionClassifierNodeType } from './types'
|
||||||
import useNodeCrud from '@/app/components/workflow/nodes/_base/hooks/use-node-crud'
|
import useNodeCrud from '@/app/components/workflow/nodes/_base/hooks/use-node-crud'
|
||||||
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'
|
||||||
@ -28,7 +29,7 @@ const useConfig = (id: string, payload: QuestionClassifierNodeType) => {
|
|||||||
inputRef.current = inputs
|
inputRef.current = inputs
|
||||||
}, [inputs])
|
}, [inputs])
|
||||||
|
|
||||||
// model
|
const [modelChanged, setModelChanged] = useState(false)
|
||||||
const {
|
const {
|
||||||
currentProvider,
|
currentProvider,
|
||||||
currentModel,
|
currentModel,
|
||||||
@ -38,6 +39,21 @@ const useConfig = (id: string, payload: QuestionClassifierNodeType) => {
|
|||||||
const modelMode = inputs.model?.mode
|
const modelMode = inputs.model?.mode
|
||||||
const isChatModel = modelMode === 'chat'
|
const isChatModel = modelMode === 'chat'
|
||||||
|
|
||||||
|
const {
|
||||||
|
isVisionModel,
|
||||||
|
handleVisionResolutionEnabledChange,
|
||||||
|
handleVisionResolutionChange,
|
||||||
|
handleModelChanged: handleVisionConfigAfterModelChanged,
|
||||||
|
} = useConfigVision(model, {
|
||||||
|
payload: inputs.vision,
|
||||||
|
onChange: (newPayload) => {
|
||||||
|
const newInputs = produce(inputs, (draft) => {
|
||||||
|
draft.vision = newPayload
|
||||||
|
})
|
||||||
|
setInputs(newInputs)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
const handleModelChanged = useCallback((model: { provider: string; modelId: string; mode?: string }) => {
|
const handleModelChanged = useCallback((model: { provider: string; modelId: string; mode?: string }) => {
|
||||||
const newInputs = produce(inputRef.current, (draft) => {
|
const newInputs = produce(inputRef.current, (draft) => {
|
||||||
draft.model.provider = model.provider
|
draft.model.provider = model.provider
|
||||||
@ -45,6 +61,7 @@ const useConfig = (id: string, payload: QuestionClassifierNodeType) => {
|
|||||||
draft.model.mode = model.mode!
|
draft.model.mode = model.mode!
|
||||||
})
|
})
|
||||||
setInputs(newInputs)
|
setInputs(newInputs)
|
||||||
|
setModelChanged(true)
|
||||||
}, [setInputs])
|
}, [setInputs])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -64,6 +81,15 @@ const useConfig = (id: string, payload: QuestionClassifierNodeType) => {
|
|||||||
setInputs(newInputs)
|
setInputs(newInputs)
|
||||||
}, [inputs, setInputs])
|
}, [inputs, setInputs])
|
||||||
|
|
||||||
|
// 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 handleQueryVarChange = useCallback((newVar: ValueSelector | string) => {
|
const handleQueryVarChange = useCallback((newVar: ValueSelector | string) => {
|
||||||
const newInputs = produce(inputs, (draft) => {
|
const newInputs = produce(inputs, (draft) => {
|
||||||
draft.query_variable_selector = newVar as ValueSelector
|
draft.query_variable_selector = newVar as ValueSelector
|
||||||
@ -191,6 +217,9 @@ const useConfig = (id: string, payload: QuestionClassifierNodeType) => {
|
|||||||
inputVarValues,
|
inputVarValues,
|
||||||
setInputVarValues,
|
setInputVarValues,
|
||||||
handleMemoryChange,
|
handleMemoryChange,
|
||||||
|
isVisionModel,
|
||||||
|
handleVisionResolutionEnabledChange,
|
||||||
|
handleVisionResolutionChange,
|
||||||
isShowSingleRun,
|
isShowSingleRun,
|
||||||
hideSingleRun,
|
hideSingleRun,
|
||||||
runningStatus,
|
runningStatus,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user