jan/web/utils/componentSettings.ts
NamH c580b4c848
feat: add engine settings (#1199)
* feat: add engine settings

Signed-off-by: James <james@jan.ai>
---------

Signed-off-by: James <james@jan.ai>
Co-authored-by: Louis <louis@jan.ai>
2023-12-28 09:11:37 +07:00

40 lines
1.6 KiB
TypeScript

import { ModelRuntimeParams, ModelSettingParams } from '@janhq/core'
import { presetConfiguration } from '@/screens/Chat/ModelSetting/predefinedComponent'
import { SettingComponentData } from '@/screens/Chat/ModelSetting/settingComponentBuilder'
import { ModelParams } from '@/helpers/atoms/Thread.atom'
export const getConfigurationsData = (
settings: ModelSettingParams | ModelRuntimeParams
) => {
const componentData: SettingComponentData[] = []
Object.keys(settings).forEach((key: string) => {
const componentSetting = presetConfiguration[key]
if (!componentSetting) {
return
}
if ('slider' === componentSetting.controllerType) {
const value = Number(settings[key as keyof ModelParams])
if ('value' in componentSetting.controllerData)
componentSetting.controllerData.value = value
} else if ('input' === componentSetting.controllerType) {
const value = settings[key as keyof ModelParams] as string
const placeholder = settings[key as keyof ModelParams] as string
if ('value' in componentSetting.controllerData)
componentSetting.controllerData.value = value
if ('placeholder' in componentSetting.controllerData)
componentSetting.controllerData.placeholder = placeholder
} else if ('checkbox' === componentSetting.controllerType) {
const checked = settings[key as keyof ModelParams] as boolean
if ('checked' in componentSetting.controllerData)
componentSetting.controllerData.checked = checked
}
componentData.push(componentSetting)
})
return componentData
}