Commit c3f99779 authored by Joel's avatar Joel

feat: vision config

parent 0518da1e
......@@ -33,7 +33,10 @@ const Filed: FC<Props> = ({
<div className='flex items-center h-6'>
<div className='text-xs font-medium text-gray-700 uppercase'>{title}</div>
{tooltip && (
<TooltipPlus popupContent={tooltip}>
<TooltipPlus popupContent={
<div className='w-[120px]'>
{tooltip}
</div>}>
<HelpCircle className='w-3.5 h-3.5 ml-0.5 text-gray-400' />
</TooltipPlus>
)}
......
'use client'
import type { FC } from 'react'
import React, { useCallback } from 'react'
import { useTranslation } from 'react-i18next'
import cn from 'classnames'
import { Resolution } from '@/types/app'
const i18nPrefix = 'workflow.nodes.llm'
type ItemProps = {
title: string
value: Resolution
onSelect: (value: Resolution) => void
isSelected: boolean
}
const Item: FC<ItemProps> = ({ title, value, onSelect, isSelected }) => {
const handleSelect = useCallback(() => {
if (isSelected)
return
onSelect(value)
}, [value, onSelect, isSelected])
return (
<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')}
onClick={handleSelect}
>
{title}
</div>
)
}
type Props = {
value: Resolution
onChange: (value: Resolution) => void
}
const ResolutionPicker: FC<Props> = ({
value,
onChange,
}) => {
const { t } = useTranslation()
return (
<div className='flex items-center'>
<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'>
<Item
title={t(`${i18nPrefix}.resolution.high`)}
value={Resolution.high}
onSelect={onChange}
isSelected={value === Resolution.high}
/>
<Item
title={t(`${i18nPrefix}.resolution.low`)}
value={Resolution.low}
onSelect={onChange}
isSelected={value === Resolution.low}
/>
</div>
</div>
)
}
export default React.memo(ResolutionPicker)
......@@ -40,8 +40,7 @@ export const mockData: LLMNodeType = {
variable_selector: ['aaa', 'name'],
},
vision: {
enabled: false,
variable_selector: [],
enabled: true,
configs: {
detail: Resolution.low,
},
......
......@@ -4,6 +4,7 @@ import MemoryConfig from '../_base/components/memory-config'
import VarReferencePicker from '../_base/components/variable/var-reference-picker'
import useConfig from './use-config'
import { mockData } from './mock'
import ResolutionPicker from './components/resolution-picker'
import VarList from '@/app/components/workflow/nodes/_base/components/variable/var-list'
import Field from '@/app/components/workflow/nodes/_base/components/field'
import AddButton from '@/app/components/base/button/add-button'
......@@ -25,6 +26,7 @@ const Panel: FC = () => {
handleAddVariable,
handleContextVarChange,
handleMemoryChange,
handleVisionResolutionChange,
} = useConfig(mockData)
const isChatApp = true // TODO: get from app context
const model = inputs.model
......@@ -106,10 +108,14 @@ const Panel: FC = () => {
{/* Vision: GPT4-vision and so on */}
<Field
title={t(`${i18nPrefix}.vision`)}
inline
>
Vision
</Field>
tooltip={t('appDebug.vision.description')!}
operations={
<ResolutionPicker
value={inputs.vision.configs.detail}
onChange={handleVisionResolutionChange}
/>
}
/>
</div>
<Split />
<div className='px-4 pt-4 pb-2'>
......
......@@ -12,7 +12,6 @@ export type LLMNodeType = CommonNodeType & {
}
vision: {
enabled: boolean
variable_selector: ValueSelector
configs: {
detail: Resolution
}
......
......@@ -3,6 +3,7 @@ import produce from 'immer'
import useVarList from '../_base/hooks/use-var-list'
import type { Memory, ValueSelector } from '../../types'
import type { LLMNodeType } from './types'
import type { Resolution } from '@/types/app'
const useConfig = (initInputs: LLMNodeType) => {
const [inputs, setInputs] = useState<LLMNodeType>(initInputs)
......@@ -45,6 +46,13 @@ const useConfig = (initInputs: LLMNodeType) => {
setInputs(newInputs)
}, [inputs, setInputs])
const handleVisionResolutionChange = useCallback((newResolution: Resolution) => {
const newInputs = produce(inputs, (draft) => {
draft.vision.configs.detail = newResolution
})
setInputs(newInputs)
}, [inputs, setInputs])
return {
inputs,
handleModelChanged,
......@@ -53,6 +61,7 @@ const useConfig = (initInputs: LLMNodeType) => {
handleAddVariable,
handleContextVarChange,
handleMemoryChange,
handleVisionResolutionChange,
}
}
......
......@@ -50,6 +50,11 @@ const translation = {
contextTooltip: 'You can import Knowledge as context',
prompt: 'prompt',
vision: 'vision',
resolution: {
name: 'Resolution',
high: 'High',
low: 'Low',
},
outputVars: {
output: 'Generate content',
usage: 'Model Usage Information',
......
......@@ -50,6 +50,11 @@ const translation = {
contextTooltip: '您可以导入知识库作为上下文',
prompt: '提示词',
vision: '视觉',
resolution: {
name: '分辨率',
high: '高',
low: '低',
},
outputVars: {
output: '生成内容',
usage: '模型用量信息',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment