NamH 7a148ea025
feat(ModelSetting): #1065 update state of model setting between threads (#1090)
Signed-off-by: James <james@jan.ai>
Co-authored-by: James <james@jan.ai>
2023-12-19 13:15:15 +07:00

48 lines
1.3 KiB
TypeScript

import { useForm } from 'react-hook-form'
import { ModelRuntimeParams } from '@janhq/core'
import { useAtomValue } from 'jotai'
import { presetConfiguration } from './predefinedComponent'
import settingComponentBuilder, {
SettingComponentData,
} from './settingComponentBuilder'
import { getActiveThreadModelRuntimeParamsAtom } from '@/helpers/atoms/Thread.atom'
export default function ModelSetting() {
const { register } = useForm()
const activeModelParams = useAtomValue(getActiveThreadModelRuntimeParamsAtom)
if (!activeModelParams) {
return null
}
const componentData: SettingComponentData[] = []
Object.keys(activeModelParams).forEach((key) => {
const componentSetting = presetConfiguration[key]
if (componentSetting) {
if ('value' in componentSetting.controllerData) {
componentSetting.controllerData.value = Number(
activeModelParams[key as keyof ModelRuntimeParams]
)
} else if ('checked' in componentSetting.controllerData) {
const checked = activeModelParams[
key as keyof ModelRuntimeParams
] as boolean
componentSetting.controllerData.checked = checked
}
componentData.push(componentSetting)
}
})
return (
<form className="flex flex-col">
{settingComponentBuilder(componentData, register)}
</form>
)
}