fix: broken stop word input - support multiple stop words (#2762)
This commit is contained in:
parent
8c3dd3a1af
commit
54af9f9e43
@ -34,13 +34,10 @@ export default function useUpdateModelParameters() {
|
|||||||
|
|
||||||
const updateModelParameter = useCallback(
|
const updateModelParameter = useCallback(
|
||||||
async (thread: Thread, settings: UpdateModelParameter) => {
|
async (thread: Thread, settings: UpdateModelParameter) => {
|
||||||
const params = settings.modelId
|
const toUpdateSettings = processStopWords(settings.params ?? {})
|
||||||
? settings.params
|
const updatedModelParams = settings.modelId
|
||||||
: { ...activeModelParams, ...settings.params }
|
? toUpdateSettings
|
||||||
|
: { ...activeModelParams, ...toUpdateSettings }
|
||||||
const updatedModelParams: ModelParams = {
|
|
||||||
...params,
|
|
||||||
}
|
|
||||||
|
|
||||||
// update the state
|
// update the state
|
||||||
setThreadModelParams(thread.id, updatedModelParams)
|
setThreadModelParams(thread.id, updatedModelParams)
|
||||||
@ -73,5 +70,13 @@ export default function useUpdateModelParameters() {
|
|||||||
[activeModelParams, selectedModel, setThreadModelParams]
|
[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 }
|
return { updateModelParameter }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,12 +10,13 @@ export const getConfigurationsData = (
|
|||||||
|
|
||||||
Object.keys(settings).forEach((key: string) => {
|
Object.keys(settings).forEach((key: string) => {
|
||||||
const componentSetting = presetConfiguration[key]
|
const componentSetting = presetConfiguration[key]
|
||||||
|
const keySetting = settings[key as keyof typeof settings]
|
||||||
|
|
||||||
if (!componentSetting) {
|
if (!componentSetting) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if ('slider' === componentSetting.controllerType) {
|
if ('slider' === componentSetting.controllerType) {
|
||||||
const value = Number(settings[key as keyof typeof settings])
|
const value = Number(keySetting)
|
||||||
if ('value' in componentSetting.controllerProps) {
|
if ('value' in componentSetting.controllerProps) {
|
||||||
componentSetting.controllerProps.value = value
|
componentSetting.controllerProps.value = value
|
||||||
if ('max' in componentSetting.controllerProps) {
|
if ('max' in componentSetting.controllerProps) {
|
||||||
@ -36,14 +37,29 @@ export const getConfigurationsData = (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if ('input' === componentSetting.controllerType) {
|
} else if ('input' === componentSetting.controllerType) {
|
||||||
const value = settings[key as keyof typeof settings] as string
|
const value =
|
||||||
const placeholder = settings[key as keyof typeof settings] as string
|
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)
|
if ('value' in componentSetting.controllerProps)
|
||||||
componentSetting.controllerProps.value = value
|
componentSetting.controllerProps.value = value
|
||||||
if ('placeholder' in componentSetting.controllerProps)
|
if ('placeholder' in componentSetting.controllerProps)
|
||||||
componentSetting.controllerProps.placeholder = placeholder
|
componentSetting.controllerProps.placeholder = placeholder
|
||||||
} else if ('checkbox' === componentSetting.controllerType) {
|
} 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)
|
if ('value' in componentSetting.controllerProps)
|
||||||
componentSetting.controllerProps.value = checked
|
componentSetting.controllerProps.value = checked
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user