Преглед на файлове

fix: vision config doesn't enabled in llm (#3225)

tags/0.6.1
Joel преди 1 година
родител
ревизия
269432a5e6
No account linked to committer's email address

+ 2
- 2
web/app/components/workflow/nodes/llm/components/resolution-picker.tsx Целия файл



return ( return (
<div <div
className={cn(isSelected ? 'bg-white border-[2px] border-primary-400 shadow-xs' : 'bg-gray-25 border border-gray-100', 'flex items-center h-8 px-3 rounded-xl text-[13px] font-normal text-gray-900 cursor-pointer')}
className={cn(isSelected ? 'bg-white border-[2px] border-primary-400 shadow-xs' : 'bg-gray-25 border border-gray-100', 'flex items-center h-8 px-3 rounded-lg text-[13px] font-normal text-gray-900 cursor-pointer')}
onClick={handleSelect} onClick={handleSelect}
> >
{title} {title}
const { t } = useTranslation() const { t } = useTranslation()


return ( return (
<div className='flex items-center'>
<div className='flex items-center justify-between'>
<div className='mr-2 text-xs font-medium text-gray-500 uppercase'>{t(`${i18nPrefix}.resolution.name`)}</div> <div className='mr-2 text-xs font-medium text-gray-500 uppercase'>{t(`${i18nPrefix}.resolution.name`)}</div>
<div className='flex items-center space-x-1'> <div className='flex items-center space-x-1'>
<Item <Item

+ 14
- 5
web/app/components/workflow/nodes/llm/panel.tsx Целия файл

import TooltipPlus from '@/app/components/base/tooltip-plus' import TooltipPlus from '@/app/components/base/tooltip-plus'
import { HelpCircle } from '@/app/components/base/icons/src/vender/line/general' import { HelpCircle } from '@/app/components/base/icons/src/vender/line/general'
import Editor from '@/app/components/workflow/nodes/_base/components/prompt/editor' import Editor from '@/app/components/workflow/nodes/_base/components/prompt/editor'
import Switch from '@/app/components/base/switch'
const i18nPrefix = 'workflow.nodes.llm' const i18nPrefix = 'workflow.nodes.llm'


const Panel: FC<NodePanelProps<LLMNodeType>> = ({ const Panel: FC<NodePanelProps<LLMNodeType>> = ({
filterVar, filterVar,
handlePromptChange, handlePromptChange,
handleMemoryChange, handleMemoryChange,
handleVisionResolutionEnabledChange,
handleVisionResolutionChange, handleVisionResolutionChange,
isShowSingleRun, isShowSingleRun,
hideSingleRun, hideSingleRun,
title={t(`${i18nPrefix}.vision`)} title={t(`${i18nPrefix}.vision`)}
tooltip={t('appDebug.vision.description')!} tooltip={t('appDebug.vision.description')!}
operations={ operations={
<ResolutionPicker
value={inputs.vision.configs?.detail || Resolution.high}
onChange={handleVisionResolutionChange}
/>
<Switch size='md' defaultValue={inputs.vision.enabled} onChange={handleVisionResolutionEnabledChange} />
} }
/>
>
{inputs.vision.enabled
? (
<ResolutionPicker
value={inputs.vision.configs?.detail || Resolution.high}
onChange={handleVisionResolutionChange}
/>
)
: null}

</Field>
</> </>
)} )}
</div> </div>

+ 54
- 1
web/app/components/workflow/nodes/llm/use-config.ts Целия файл

// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [defaultConfig, isChatModel]) }, [defaultConfig, isChatModel])


const [modelChanged, setModelChanged] = useState(false)
const { const {
currentProvider, currentProvider,
currentModel, currentModel,
appendDefaultPromptConfig(draft, defaultConfig, model.mode === 'chat') appendDefaultPromptConfig(draft, defaultConfig, model.mode === 'chat')
}) })
setInputs(newInputs) setInputs(newInputs)
setModelChanged(true)
}, [setInputs, defaultConfig, appendDefaultPromptConfig]) }, [setInputs, defaultConfig, appendDefaultPromptConfig])


useEffect(() => { useEffect(() => {
}, },
) )
const isShowVisionConfig = !!currModel?.features?.includes(ModelFeatureEnum.vision) const isShowVisionConfig = !!currModel?.features?.includes(ModelFeatureEnum.vision)

// change to vision model to set vision enabled, else disabled
useEffect(() => {
if (!modelChanged)
return
setModelChanged(false)
if (!isShowVisionConfig) {
const newInputs = produce(inputs, (draft) => {
draft.vision = {
enabled: false,
}
})
setInputs(newInputs)
return
}
if (!inputs.vision?.enabled) {
const newInputs = produce(inputs, (draft) => {
if (!draft.vision?.enabled) {
draft.vision = {
enabled: true,
configs: {
detail: Resolution.high,
},
}
}
})
setInputs(newInputs)
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isShowVisionConfig, modelChanged])
// variables // variables
const { handleVarListChange, handleAddVariable } = useVarList<LLMNodeType>({ const { handleVarListChange, handleAddVariable } = useVarList<LLMNodeType>({
inputs, inputs,
setInputs(newInputs) setInputs(newInputs)
}, [inputs, setInputs]) }, [inputs, setInputs])


const handleVisionResolutionEnabledChange = useCallback((enabled: boolean) => {
const newInputs = produce(inputs, (draft) => {
if (!draft.vision) {
draft.vision = {
enabled,
configs: {
detail: Resolution.high,
},
}
}
else {
draft.vision.enabled = enabled
if (!draft.vision.configs) {
draft.vision.configs = {
detail: Resolution.high,
}
}
}
})
setInputs(newInputs)
}, [inputs, setInputs])

const handleVisionResolutionChange = useCallback((newResolution: Resolution) => { const handleVisionResolutionChange = useCallback((newResolution: Resolution) => {
const newInputs = produce(inputs, (draft) => { const newInputs = produce(inputs, (draft) => {
if (!draft.vision.configs) { if (!draft.vision.configs) {
filterVar, filterVar,
handlePromptChange, handlePromptChange,
handleMemoryChange, handleMemoryChange,
handleVisionResolutionEnabledChange,
handleVisionResolutionChange, handleVisionResolutionChange,
isShowSingleRun, isShowSingleRun,
hideSingleRun, hideSingleRun,

Loading…
Отказ
Запис