fix: broken stop word input - support multiple stop words (#2762)

This commit is contained in:
Louis 2024-04-21 17:54:41 +07:00 committed by GitHub
parent 8c3dd3a1af
commit 54af9f9e43
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 32 additions and 11 deletions

View File

@ -34,13 +34,10 @@ export default function useUpdateModelParameters() {
const updateModelParameter = useCallback(
async (thread: Thread, settings: UpdateModelParameter) => {
const params = settings.modelId
? settings.params
: { ...activeModelParams, ...settings.params }
const updatedModelParams: ModelParams = {
...params,
}
const toUpdateSettings = processStopWords(settings.params ?? {})
const updatedModelParams = settings.modelId
? toUpdateSettings
: { ...activeModelParams, ...toUpdateSettings }
// update the state
setThreadModelParams(thread.id, updatedModelParams)
@ -73,5 +70,13 @@ export default function useUpdateModelParameters() {
[activeModelParams, selectedModel, setThreadModelParams]
)
const processStopWords = (params: ModelParams): ModelParams => {
if ('stop' in params && typeof params['stop'] === 'string') {
// Input as string but stop words accept an array of strings (space as separator)
params['stop'] = (params['stop'] as string).split(' ')
}
return params
}
return { updateModelParameter }
}

View File

@ -10,12 +10,13 @@ export const getConfigurationsData = (
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(settings[key as keyof typeof settings])
const value = Number(keySetting)
if ('value' in componentSetting.controllerProps) {
componentSetting.controllerProps.value = value
if ('max' in componentSetting.controllerProps) {
@ -36,14 +37,29 @@ export const getConfigurationsData = (
}
}
} else if ('input' === componentSetting.controllerType) {
const value = settings[key as keyof typeof settings] as string
const placeholder = settings[key as keyof typeof settings] as string
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 = settings[key as keyof typeof settings] as boolean
const checked = keySetting as boolean
if ('value' in componentSetting.controllerProps)
componentSetting.controllerProps.value = checked