Commit c3f99779 authored by Joel's avatar Joel

feat: vision config

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