| import { Model, SettingComponentProps } from '@janhq/core' |
|
|
| import { presetConfiguration } from './predefinedComponent' |
|
|
| export const getConfigurationsData = ( |
| settings: object, |
| selectedModel?: Model |
| ): SettingComponentProps[] => { |
| const componentData: SettingComponentProps[] = [] |
|
|
| Object.keys(settings).forEach((key: string) => { |
| const componentSetting = presetConfiguration[key] |
| const keySetting = settings[key as keyof typeof settings] |
|
|
| if (!componentSetting) { |
| return |
| } |
| if ('slider' === componentSetting.controllerType) { |
| const value = Number(keySetting) |
| if ('value' in componentSetting.controllerProps) { |
| componentSetting.controllerProps.value = value |
| if ('max' in componentSetting.controllerProps) { |
| switch (key) { |
| case 'max_tokens': |
| componentSetting.controllerProps.max = |
| selectedModel?.parameters.max_tokens || |
| componentSetting.controllerProps.max || |
| 4096 |
| break |
| case 'ctx_len': |
| componentSetting.controllerProps.max = |
| selectedModel?.settings.ctx_len || |
| componentSetting.controllerProps.max || |
| 2048 |
| break |
| } |
| } |
| } |
| } else if ('input' === componentSetting.controllerType) { |
| const value = |
| typeof keySetting === 'object' && Array.isArray(keySetting) |
| ? |
| |
| (keySetting as string[]) |
| .filter((e) => e.trim() !== '') |
| .join(' ') |
| .concat( |
| |
| (keySetting as string[])[ |
| (keySetting as string[]).length - 1 |
| ] === '' |
| ? ' ' |
| : '' |
| ) |
| : (keySetting as string) |
| const placeholder = keySetting as string |
| if ('value' in componentSetting.controllerProps) |
| componentSetting.controllerProps.value = value |
| if ('placeholder' in componentSetting.controllerProps) |
| componentSetting.controllerProps.placeholder = placeholder |
| } else if ('checkbox' === componentSetting.controllerType) { |
| const checked = keySetting as boolean |
|
|
| if ('value' in componentSetting.controllerProps) |
| componentSetting.controllerProps.value = checked |
| } |
| componentData.push(componentSetting) |
| }) |
| return componentData |
| } |
|
|