fix: max value of max_tokens should follow context_length's value (#2969)

Signed-off-by: James <james@jan.ai>
Co-authored-by: James <james@jan.ai>
This commit is contained in:
NamH 2024-05-30 19:01:00 +07:00 committed by GitHub
parent 93ce01051c
commit 8dbb8d6536
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,5 +1,6 @@
import { memo, useCallback, useMemo } from 'react' import { memo, useCallback, useMemo } from 'react'
import { SettingComponentProps, SliderComponentProps } from '@janhq/core/.'
import { import {
Tabs, Tabs,
TabsContent, TabsContent,
@ -51,27 +52,63 @@ const ThreadRightPanel = () => {
const { stopModel } = useActiveModel() const { stopModel } = useActiveModel()
const { updateModelParameter } = useUpdateModelParameters() const { updateModelParameter } = useUpdateModelParameters()
const modelSettings = useMemo(() => { const settings = useMemo(() => {
// runtime setting
const modelRuntimeParams = toRuntimeParams(activeModelParams) const modelRuntimeParams = toRuntimeParams(activeModelParams)
const componentDataRuntimeSetting = getConfigurationsData( const componentDataRuntimeSetting = getConfigurationsData(
modelRuntimeParams, modelRuntimeParams,
selectedModel selectedModel
) ).filter((x) => x.key !== 'prompt_template')
return componentDataRuntimeSetting.filter(
(x) => x.key !== 'prompt_template'
)
}, [activeModelParams, selectedModel])
const engineSettings = useMemo(() => { // engine setting
const modelEngineParams = toSettingParams(activeModelParams) const modelEngineParams = toSettingParams(activeModelParams)
const componentDataEngineSetting = getConfigurationsData( const componentDataEngineSetting = getConfigurationsData(
modelEngineParams, modelEngineParams,
selectedModel selectedModel
).filter((x) => x.key !== 'prompt_template' && x.key !== 'embedding')
// the max value of max token has to follow context length
const maxTokens = componentDataRuntimeSetting.find(
(x) => x.key === 'max_tokens'
) )
return componentDataEngineSetting.filter( const contextLength = componentDataEngineSetting.find(
(x) => x.key !== 'prompt_template' && x.key !== 'embedding' (x) => x.key === 'ctx_len'
) )
if (maxTokens && contextLength) {
// replace maxToken to componentDataRuntimeSetting
const updatedComponentDataRuntimeSetting: SettingComponentProps[] =
componentDataRuntimeSetting.map((settingComponentProps) => {
if (settingComponentProps.key !== 'max_tokens')
return settingComponentProps
const contextLengthValue = Number(contextLength.controllerProps.value)
const maxTokenValue = Number(
settingComponentProps.controllerProps.value
)
const controllerProps =
settingComponentProps.controllerProps as SliderComponentProps
const sliderProps: SliderComponentProps = {
...controllerProps,
max: contextLengthValue,
value: Math.min(maxTokenValue, contextLengthValue),
}
const updatedSettingProps: SettingComponentProps = {
...settingComponentProps,
controllerProps: sliderProps,
}
return updatedSettingProps
})
return {
runtimeSettings: updatedComponentDataRuntimeSetting,
engineSettings: componentDataEngineSetting,
}
}
return {
runtimeSettings: componentDataRuntimeSetting,
engineSettings: componentDataEngineSetting,
}
}, [activeModelParams, selectedModel]) }, [activeModelParams, selectedModel])
const promptTemplateSettings = useMemo(() => { const promptTemplateSettings = useMemo(() => {
@ -179,13 +216,13 @@ const ThreadRightPanel = () => {
<ModelDropdown /> <ModelDropdown />
</div> </div>
<Accordion defaultValue={[]}> <Accordion defaultValue={[]}>
{modelSettings.length !== 0 && ( {settings.runtimeSettings.length !== 0 && (
<AccordionItem <AccordionItem
title="Inference Parameters" title="Inference Parameters"
value="Inference Parameters" value="Inference Parameters"
> >
<ModelSetting <ModelSetting
componentProps={modelSettings} componentProps={settings.runtimeSettings}
onValueChanged={onValueChanged} onValueChanged={onValueChanged}
/> />
</AccordionItem> </AccordionItem>
@ -197,13 +234,13 @@ const ThreadRightPanel = () => {
</AccordionItem> </AccordionItem>
)} )}
{engineSettings.length !== 0 && ( {settings.engineSettings.length !== 0 && (
<AccordionItem <AccordionItem
title="Engine Parameters" title="Engine Parameters"
value="Engine Parameters" value="Engine Parameters"
> >
<EngineSetting <EngineSetting
componentData={engineSettings} componentData={settings.engineSettings}
onValueChanged={onValueChanged} onValueChanged={onValueChanged}
/> />
</AccordionItem> </AccordionItem>