refactor: default max_tokens and ctx_len

This commit is contained in:
Louis 2024-01-11 13:03:07 +07:00 committed by Faisal Amir
parent 5bd4637e34
commit 8b6f7e846e
11 changed files with 49 additions and 38 deletions

View File

@ -16,7 +16,7 @@ import { useActiveModel } from '@/hooks/useActiveModel'
import useUpdateModelParameters from '@/hooks/useUpdateModelParameters'
import { getConfigurationsData } from '@/utils/componentSettings'
import { toSettingParams } from '@/utils/model_param'
import { toSettingParams } from '@/utils/modelParam'
import {
engineParamsUpdateAtom,

View File

@ -16,7 +16,7 @@ import useUpdateModelParameters from '@/hooks/useUpdateModelParameters'
import { getConfigurationsData } from '@/utils/componentSettings'
import { toSettingParams } from '@/utils/model_param'
import { toSettingParams } from '@/utils/modelParam'
import {
engineParamsUpdateAtom,

View File

@ -19,9 +19,7 @@ import { useClickOutside } from '@/hooks/useClickOutside'
import useUpdateModelParameters from '@/hooks/useUpdateModelParameters'
import { getConfigurationsData } from '@/utils/componentSettings'
import { toSettingParams } from '@/utils/model_param'
import { selectedModelAtom } from '../DropdownListSidebar'
import { toSettingParams } from '@/utils/modelParam'
import {
engineParamsUpdateAtom,
@ -59,7 +57,6 @@ const SliderRightPanel: React.FC<Props> = ({
const setEngineParamsUpdate = useSetAtom(engineParamsUpdateAtom)
const selectedModel = useAtomValue(selectedModelAtom)
const { stopModel } = useActiveModel()
const [showTooltip, setShowTooltip] = useState({ max: false, min: false })
@ -77,19 +74,6 @@ const SliderRightPanel: React.FC<Props> = ({
updateModelParameter(threadId, name, e[0])
}
const maxValue = (name: string) => {
switch (name) {
case 'max_tokens':
return selectedModel?.parameters.max_tokens || max
case 'ctx_len':
return selectedModel?.settings.ctx_len || max
default:
return max
}
}
return (
<div className="flex flex-col">
<div className="mb-3 flex items-center gap-x-2">
@ -114,12 +98,12 @@ const SliderRightPanel: React.FC<Props> = ({
value={[value]}
onValueChange={onValueChanged}
min={min}
max={maxValue(name)}
max={max}
step={step}
/>
<div className="relative mt-2 flex items-center justify-between text-gray-400">
<p className="text-sm">{min}</p>
<p className="text-sm">{maxValue(name) as number}</p>
<p className="text-sm">{max}</p>
</div>
</div>
<Tooltip open={showTooltip.max || showTooltip.min}>
@ -128,11 +112,11 @@ const SliderRightPanel: React.FC<Props> = ({
type="number"
className="-mt-4 h-8 w-20"
min={min}
max={maxValue(name)}
max={max}
value={String(value)}
onChange={(e) => {
if (Number(e.target.value) > Number(maxValue(name))) {
onValueChanged([Number(maxValue(name))])
if (Number(e.target.value) > Number(max)) {
onValueChanged([Number(max)])
setShowTooltip({ max: true, min: false })
} else if (Number(e.target.value) < Number(min)) {
onValueChanged([Number(min)])

View File

@ -23,7 +23,7 @@ import { currentPromptAtom } from '@/containers/Providers/Jotai'
import { toaster } from '@/containers/Toast'
import { toRuntimeParams, toSettingParams } from '@/utils/model_param'
import { toRuntimeParams, toSettingParams } from '@/utils/modelParam'
import { useActiveModel } from './useActiveModel'

View File

@ -8,7 +8,7 @@ import {
import { useAtomValue, useSetAtom } from 'jotai'
import { toRuntimeParams, toSettingParams } from '@/utils/model_param'
import { toRuntimeParams, toSettingParams } from '@/utils/modelParam'
import { extensionManager } from '@/extension'
import {

View File

@ -4,7 +4,7 @@ import { useAtomValue } from 'jotai'
import { selectedModelAtom } from '@/containers/DropdownListSidebar'
import { getConfigurationsData } from '@/utils/componentSettings'
import { toSettingParams } from '@/utils/model_param'
import { toSettingParams } from '@/utils/modelParam'
import settingComponentBuilder from '../ModelSetting/settingComponentBuilder'
@ -18,7 +18,7 @@ const EngineSetting = () => {
const modelSettingParams = toSettingParams(activeModelParams)
const componentData = getConfigurationsData(modelSettingParams)
const componentData = getConfigurationsData(modelSettingParams, selectedModel)
componentData.sort((a, b) => a.title.localeCompare(b.title))

View File

@ -6,7 +6,7 @@ import { useAtomValue } from 'jotai'
import { selectedModelAtom } from '@/containers/DropdownListSidebar'
import { getConfigurationsData } from '@/utils/componentSettings'
import { toRuntimeParams } from '@/utils/model_param'
import { toRuntimeParams } from '@/utils/modelParam'
import settingComponentBuilder from './settingComponentBuilder'
@ -20,9 +20,10 @@ const ModelSetting = () => {
const modelRuntimeParams = toRuntimeParams(activeModelParams)
const componentData = getConfigurationsData(modelRuntimeParams)
componentData.sort((a, b) => a.title.localeCompare(b.title))
const componentData = getConfigurationsData(
modelRuntimeParams,
selectedModel
).toSorted((a, b) => a.title.localeCompare(b.title))
return (
<div className="flex flex-col">

View File

@ -1,7 +1,7 @@
/* eslint-disable no-case-declarations */
import Checkbox from '@/containers/Checkbox'
import ModelConfigInput from '@/containers/ModelConfigInput'
import Slider from '@/containers/Slider'
import SliderRightPanel from '@/containers/SliderRightPanel'
export type ControllerType = 'slider' | 'checkbox' | 'input'
@ -43,7 +43,7 @@ const settingComponentBuilder = (
case 'slider':
const { min, max, step, value } = data.controllerData as SliderData
return (
<Slider
<SliderRightPanel
key={data.name}
title={data.title}
description={data.description}

View File

@ -19,7 +19,7 @@ import DropdownListSidebar, {
import { useCreateNewThread } from '@/hooks/useCreateNewThread'
import { getConfigurationsData } from '@/utils/componentSettings'
import { toRuntimeParams, toSettingParams } from '@/utils/model_param'
import { toRuntimeParams, toSettingParams } from '@/utils/modelParam'
import EngineSetting from '../EngineSetting'
import ModelSetting from '../ModelSetting'

View File

@ -1,4 +1,4 @@
import { ModelRuntimeParams, ModelSettingParams } from '@janhq/core'
import { Model, ModelRuntimeParams, ModelSettingParams } from '@janhq/core'
import { presetConfiguration } from '@/screens/Chat/ModelSetting/predefinedComponent'
@ -7,9 +7,16 @@ import { SettingComponentData } from '@/screens/Chat/ModelSetting/settingCompone
import { ModelParams } from '@/helpers/atoms/Thread.atom'
export const getConfigurationsData = (
settings: ModelSettingParams | ModelRuntimeParams
settings: ModelSettingParams | ModelRuntimeParams,
selectedModel?: Model
) => {
const componentData: SettingComponentData[] = []
const defaultValue = (value?: number) => {
if (value && value < 4096) return value
return 4096
}
Object.keys(settings).forEach((key: string) => {
const componentSetting = presetConfiguration[key]
@ -18,8 +25,27 @@ export const getConfigurationsData = (
}
if ('slider' === componentSetting.controllerType) {
const value = Number(settings[key as keyof ModelParams])
if ('value' in componentSetting.controllerData)
if ('value' in componentSetting.controllerData) {
componentSetting.controllerData.value = value
if ('max' in componentSetting.controllerData) {
switch (key) {
case 'max_tokens':
componentSetting.controllerData.max =
selectedModel?.parameters.max_tokens || 4096
componentSetting.controllerData.value = defaultValue(
selectedModel?.parameters.max_tokens
)
break
case 'ctx_len':
componentSetting.controllerData.max =
selectedModel?.settings.ctx_len || 4096
componentSetting.controllerData.value = defaultValue(
selectedModel?.settings.ctx_len
)
break
}
}
}
} else if ('input' === componentSetting.controllerType) {
const value = settings[key as keyof ModelParams] as string
const placeholder = settings[key as keyof ModelParams] as string