feat: default set vision var value

This commit is contained in:
Joel 2024-08-28 14:35:49 +08:00
parent c34fc071e0
commit 94e40d4ed9
2 changed files with 13 additions and 5 deletions

View File

@ -1,5 +1,6 @@
import produce from 'immer'
import { useCallback } from 'react'
import { useIsChatMode } from './use-workflow'
import type { ModelConfig, VisionSetting } from '@/app/components/workflow/types'
import { useTextGenerationCurrentProviderAndModelAndModelList } from '@/app/components/header/account-setting/model-provider-page/hooks'
import {
@ -31,6 +32,8 @@ const useConfigVision = (model: ModelConfig, {
},
)
const isChatMode = useIsChatMode()
const getIsVisionModel = useCallback(() => {
return !!currModel?.features?.includes(ModelFeatureEnum.vision)
}, [currModel])
@ -40,9 +43,15 @@ const useConfigVision = (model: ModelConfig, {
const handleVisionResolutionEnabledChange = useCallback((enabled: boolean) => {
const newPayload = produce(payload, (draft) => {
draft.enabled = enabled
if (enabled && isChatMode) {
draft.configs = {
detail: Resolution.high,
variable_selector: ['sys', 'files'],
}
}
})
onChange(newPayload)
}, [onChange, payload])
}, [isChatMode, onChange, payload])
const handleVisionResolutionChange = useCallback((config: VisionSetting) => {
const newPayload = produce(payload, (draft) => {

View File

@ -9,7 +9,7 @@ import Field from '@/app/components/workflow/nodes/_base/components/field'
import Switch from '@/app/components/base/switch'
import { type ValueSelector, type Var, VarType, type VisionSetting } from '@/app/components/workflow/types'
import { Resolution } from '@/types/app'
import TooltipPlus from '@/app/components/base/tooltip'
import Tooltip from '@/app/components/base/tooltip'
const i18nPrefix = 'workflow.nodes.llm'
type Props = {
@ -58,13 +58,12 @@ const ConfigVision: FC<Props> = ({
title={t(`${i18nPrefix}.vision`)}
tooltip={t('appDebug.vision.description')!}
operations={
<TooltipPlus
hideArrow
<Tooltip
popupContent={t('appDebug.vision.onlySupportVisionModelTip')!}
disabled={isVisionModel}
>
<Switch disabled={readOnly || !isVisionModel} size='md' defaultValue={!isVisionModel ? false : enabled} onChange={onEnabledChange} />
</TooltipPlus>
</Tooltip>
}
>
{(enabled && isVisionModel)