jan/web/utils/componentSettings.ts
NamH ec9b5bf682
fix: update new api from cortex to support 0.5.0 (#3221)
* fix: update new api from cortex to support 0.5.0

Signed-off-by: James <namnh0122@gmail.com>

* fix stop button for streaming

Signed-off-by: James <namnh0122@gmail.com>

* fix stop inference for nonstreaming

Signed-off-by: James <namnh0122@gmail.com>

* chore: remove umami prevent tracking call to vercel

Signed-off-by: James <namnh0122@gmail.com>

* add warning modal when running more than 2 model concurrently

Signed-off-by: James <namnh0122@gmail.com>

* fix: skip summarize if abort

Signed-off-by: James <namnh0122@gmail.com>

* 0.5.0-3

* add inference error popup

Signed-off-by: James <namnh0122@gmail.com>

* add back import local model

Signed-off-by: James <namnh0122@gmail.com>

* fix: max token issue (#3225)

Signed-off-by: James <namnh0122@gmail.com>

* format status

Signed-off-by: James <namnh0122@gmail.com>

* fix migration missing instructions

Signed-off-by: James <namnh0122@gmail.com>

* fix: wait for cortex process overlay should be on top (#3224)

* fix: wait for cortex process overlay should be on top

* chore: update cortex.js

* Cortex 0.5.0-5

* add import model to my model screen

Signed-off-by: James <namnh0122@gmail.com>

* fix: should migrate symlink models (#3226)

* fix import on windows (#3229)

Signed-off-by: James <namnh0122@gmail.com>

* fix yarn lint

Signed-off-by: James <namnh0122@gmail.com>

* fix: clean up port before start jan (#3232)

Signed-off-by: James <namnh0122@gmail.com>

---------

Signed-off-by: James <namnh0122@gmail.com>
Co-authored-by: Van Pham <64197333+Van-QA@users.noreply.github.com>
Co-authored-by: Louis <louis@jan.ai>
2024-08-02 09:37:04 +07:00

66 lines
2.3 KiB
TypeScript

import { SettingComponentProps } from '@janhq/core'
import { presetConfiguration } from './predefinedComponent'
export const getConfigurationsData = (
settings: object
): 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 =
componentSetting.controllerProps.max ?? 4096
break
case 'ctx_len':
componentSetting.controllerProps.max =
componentSetting.controllerProps.max ?? 2048
break
}
}
}
} else if ('input' === componentSetting.controllerType) {
const value =
typeof keySetting === 'object' && Array.isArray(keySetting)
? // Support array input with text input
// TODO: remove this when we support muti-tag input
(keySetting as string[])
.filter((e) => e.trim() !== '')
.join(' ')
.concat(
// Keep last space to allow user to add new array element
(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
}