refactor: default max_tokens and ctx_len
This commit is contained in:
parent
5bd4637e34
commit
8b6f7e846e
@ -16,7 +16,7 @@ import { useActiveModel } from '@/hooks/useActiveModel'
|
|||||||
import useUpdateModelParameters from '@/hooks/useUpdateModelParameters'
|
import useUpdateModelParameters from '@/hooks/useUpdateModelParameters'
|
||||||
|
|
||||||
import { getConfigurationsData } from '@/utils/componentSettings'
|
import { getConfigurationsData } from '@/utils/componentSettings'
|
||||||
import { toSettingParams } from '@/utils/model_param'
|
import { toSettingParams } from '@/utils/modelParam'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
engineParamsUpdateAtom,
|
engineParamsUpdateAtom,
|
||||||
|
|||||||
@ -16,7 +16,7 @@ import useUpdateModelParameters from '@/hooks/useUpdateModelParameters'
|
|||||||
|
|
||||||
import { getConfigurationsData } from '@/utils/componentSettings'
|
import { getConfigurationsData } from '@/utils/componentSettings'
|
||||||
|
|
||||||
import { toSettingParams } from '@/utils/model_param'
|
import { toSettingParams } from '@/utils/modelParam'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
engineParamsUpdateAtom,
|
engineParamsUpdateAtom,
|
||||||
|
|||||||
@ -19,9 +19,7 @@ import { useClickOutside } from '@/hooks/useClickOutside'
|
|||||||
import useUpdateModelParameters from '@/hooks/useUpdateModelParameters'
|
import useUpdateModelParameters from '@/hooks/useUpdateModelParameters'
|
||||||
|
|
||||||
import { getConfigurationsData } from '@/utils/componentSettings'
|
import { getConfigurationsData } from '@/utils/componentSettings'
|
||||||
import { toSettingParams } from '@/utils/model_param'
|
import { toSettingParams } from '@/utils/modelParam'
|
||||||
|
|
||||||
import { selectedModelAtom } from '../DropdownListSidebar'
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
engineParamsUpdateAtom,
|
engineParamsUpdateAtom,
|
||||||
@ -59,7 +57,6 @@ const SliderRightPanel: React.FC<Props> = ({
|
|||||||
|
|
||||||
const setEngineParamsUpdate = useSetAtom(engineParamsUpdateAtom)
|
const setEngineParamsUpdate = useSetAtom(engineParamsUpdateAtom)
|
||||||
|
|
||||||
const selectedModel = useAtomValue(selectedModelAtom)
|
|
||||||
const { stopModel } = useActiveModel()
|
const { stopModel } = useActiveModel()
|
||||||
|
|
||||||
const [showTooltip, setShowTooltip] = useState({ max: false, min: false })
|
const [showTooltip, setShowTooltip] = useState({ max: false, min: false })
|
||||||
@ -77,19 +74,6 @@ const SliderRightPanel: React.FC<Props> = ({
|
|||||||
updateModelParameter(threadId, name, e[0])
|
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 (
|
return (
|
||||||
<div className="flex flex-col">
|
<div className="flex flex-col">
|
||||||
<div className="mb-3 flex items-center gap-x-2">
|
<div className="mb-3 flex items-center gap-x-2">
|
||||||
@ -114,12 +98,12 @@ const SliderRightPanel: React.FC<Props> = ({
|
|||||||
value={[value]}
|
value={[value]}
|
||||||
onValueChange={onValueChanged}
|
onValueChange={onValueChanged}
|
||||||
min={min}
|
min={min}
|
||||||
max={maxValue(name)}
|
max={max}
|
||||||
step={step}
|
step={step}
|
||||||
/>
|
/>
|
||||||
<div className="relative mt-2 flex items-center justify-between text-gray-400">
|
<div className="relative mt-2 flex items-center justify-between text-gray-400">
|
||||||
<p className="text-sm">{min}</p>
|
<p className="text-sm">{min}</p>
|
||||||
<p className="text-sm">{maxValue(name) as number}</p>
|
<p className="text-sm">{max}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Tooltip open={showTooltip.max || showTooltip.min}>
|
<Tooltip open={showTooltip.max || showTooltip.min}>
|
||||||
@ -128,11 +112,11 @@ const SliderRightPanel: React.FC<Props> = ({
|
|||||||
type="number"
|
type="number"
|
||||||
className="-mt-4 h-8 w-20"
|
className="-mt-4 h-8 w-20"
|
||||||
min={min}
|
min={min}
|
||||||
max={maxValue(name)}
|
max={max}
|
||||||
value={String(value)}
|
value={String(value)}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
if (Number(e.target.value) > Number(maxValue(name))) {
|
if (Number(e.target.value) > Number(max)) {
|
||||||
onValueChanged([Number(maxValue(name))])
|
onValueChanged([Number(max)])
|
||||||
setShowTooltip({ max: true, min: false })
|
setShowTooltip({ max: true, min: false })
|
||||||
} else if (Number(e.target.value) < Number(min)) {
|
} else if (Number(e.target.value) < Number(min)) {
|
||||||
onValueChanged([Number(min)])
|
onValueChanged([Number(min)])
|
||||||
@ -23,7 +23,7 @@ import { currentPromptAtom } from '@/containers/Providers/Jotai'
|
|||||||
|
|
||||||
import { toaster } from '@/containers/Toast'
|
import { toaster } from '@/containers/Toast'
|
||||||
|
|
||||||
import { toRuntimeParams, toSettingParams } from '@/utils/model_param'
|
import { toRuntimeParams, toSettingParams } from '@/utils/modelParam'
|
||||||
|
|
||||||
import { useActiveModel } from './useActiveModel'
|
import { useActiveModel } from './useActiveModel'
|
||||||
|
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import {
|
|||||||
|
|
||||||
import { useAtomValue, useSetAtom } from 'jotai'
|
import { useAtomValue, useSetAtom } from 'jotai'
|
||||||
|
|
||||||
import { toRuntimeParams, toSettingParams } from '@/utils/model_param'
|
import { toRuntimeParams, toSettingParams } from '@/utils/modelParam'
|
||||||
|
|
||||||
import { extensionManager } from '@/extension'
|
import { extensionManager } from '@/extension'
|
||||||
import {
|
import {
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import { useAtomValue } from 'jotai'
|
|||||||
import { selectedModelAtom } from '@/containers/DropdownListSidebar'
|
import { selectedModelAtom } from '@/containers/DropdownListSidebar'
|
||||||
|
|
||||||
import { getConfigurationsData } from '@/utils/componentSettings'
|
import { getConfigurationsData } from '@/utils/componentSettings'
|
||||||
import { toSettingParams } from '@/utils/model_param'
|
import { toSettingParams } from '@/utils/modelParam'
|
||||||
|
|
||||||
import settingComponentBuilder from '../ModelSetting/settingComponentBuilder'
|
import settingComponentBuilder from '../ModelSetting/settingComponentBuilder'
|
||||||
|
|
||||||
@ -18,7 +18,7 @@ const EngineSetting = () => {
|
|||||||
|
|
||||||
const modelSettingParams = toSettingParams(activeModelParams)
|
const modelSettingParams = toSettingParams(activeModelParams)
|
||||||
|
|
||||||
const componentData = getConfigurationsData(modelSettingParams)
|
const componentData = getConfigurationsData(modelSettingParams, selectedModel)
|
||||||
|
|
||||||
componentData.sort((a, b) => a.title.localeCompare(b.title))
|
componentData.sort((a, b) => a.title.localeCompare(b.title))
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import { useAtomValue } from 'jotai'
|
|||||||
import { selectedModelAtom } from '@/containers/DropdownListSidebar'
|
import { selectedModelAtom } from '@/containers/DropdownListSidebar'
|
||||||
|
|
||||||
import { getConfigurationsData } from '@/utils/componentSettings'
|
import { getConfigurationsData } from '@/utils/componentSettings'
|
||||||
import { toRuntimeParams } from '@/utils/model_param'
|
import { toRuntimeParams } from '@/utils/modelParam'
|
||||||
|
|
||||||
import settingComponentBuilder from './settingComponentBuilder'
|
import settingComponentBuilder from './settingComponentBuilder'
|
||||||
|
|
||||||
@ -20,9 +20,10 @@ const ModelSetting = () => {
|
|||||||
|
|
||||||
const modelRuntimeParams = toRuntimeParams(activeModelParams)
|
const modelRuntimeParams = toRuntimeParams(activeModelParams)
|
||||||
|
|
||||||
const componentData = getConfigurationsData(modelRuntimeParams)
|
const componentData = getConfigurationsData(
|
||||||
|
modelRuntimeParams,
|
||||||
componentData.sort((a, b) => a.title.localeCompare(b.title))
|
selectedModel
|
||||||
|
).toSorted((a, b) => a.title.localeCompare(b.title))
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col">
|
<div className="flex flex-col">
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
/* eslint-disable no-case-declarations */
|
/* eslint-disable no-case-declarations */
|
||||||
import Checkbox from '@/containers/Checkbox'
|
import Checkbox from '@/containers/Checkbox'
|
||||||
import ModelConfigInput from '@/containers/ModelConfigInput'
|
import ModelConfigInput from '@/containers/ModelConfigInput'
|
||||||
import Slider from '@/containers/Slider'
|
import SliderRightPanel from '@/containers/SliderRightPanel'
|
||||||
|
|
||||||
export type ControllerType = 'slider' | 'checkbox' | 'input'
|
export type ControllerType = 'slider' | 'checkbox' | 'input'
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ const settingComponentBuilder = (
|
|||||||
case 'slider':
|
case 'slider':
|
||||||
const { min, max, step, value } = data.controllerData as SliderData
|
const { min, max, step, value } = data.controllerData as SliderData
|
||||||
return (
|
return (
|
||||||
<Slider
|
<SliderRightPanel
|
||||||
key={data.name}
|
key={data.name}
|
||||||
title={data.title}
|
title={data.title}
|
||||||
description={data.description}
|
description={data.description}
|
||||||
|
|||||||
@ -19,7 +19,7 @@ import DropdownListSidebar, {
|
|||||||
import { useCreateNewThread } from '@/hooks/useCreateNewThread'
|
import { useCreateNewThread } from '@/hooks/useCreateNewThread'
|
||||||
|
|
||||||
import { getConfigurationsData } from '@/utils/componentSettings'
|
import { getConfigurationsData } from '@/utils/componentSettings'
|
||||||
import { toRuntimeParams, toSettingParams } from '@/utils/model_param'
|
import { toRuntimeParams, toSettingParams } from '@/utils/modelParam'
|
||||||
|
|
||||||
import EngineSetting from '../EngineSetting'
|
import EngineSetting from '../EngineSetting'
|
||||||
import ModelSetting from '../ModelSetting'
|
import ModelSetting from '../ModelSetting'
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { ModelRuntimeParams, ModelSettingParams } from '@janhq/core'
|
import { Model, ModelRuntimeParams, ModelSettingParams } from '@janhq/core'
|
||||||
|
|
||||||
import { presetConfiguration } from '@/screens/Chat/ModelSetting/predefinedComponent'
|
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'
|
import { ModelParams } from '@/helpers/atoms/Thread.atom'
|
||||||
|
|
||||||
export const getConfigurationsData = (
|
export const getConfigurationsData = (
|
||||||
settings: ModelSettingParams | ModelRuntimeParams
|
settings: ModelSettingParams | ModelRuntimeParams,
|
||||||
|
selectedModel?: Model
|
||||||
) => {
|
) => {
|
||||||
const componentData: SettingComponentData[] = []
|
const componentData: SettingComponentData[] = []
|
||||||
|
|
||||||
|
const defaultValue = (value?: number) => {
|
||||||
|
if (value && value < 4096) return value
|
||||||
|
return 4096
|
||||||
|
}
|
||||||
|
|
||||||
Object.keys(settings).forEach((key: string) => {
|
Object.keys(settings).forEach((key: string) => {
|
||||||
const componentSetting = presetConfiguration[key]
|
const componentSetting = presetConfiguration[key]
|
||||||
|
|
||||||
@ -18,8 +25,27 @@ export const getConfigurationsData = (
|
|||||||
}
|
}
|
||||||
if ('slider' === componentSetting.controllerType) {
|
if ('slider' === componentSetting.controllerType) {
|
||||||
const value = Number(settings[key as keyof ModelParams])
|
const value = Number(settings[key as keyof ModelParams])
|
||||||
if ('value' in componentSetting.controllerData)
|
if ('value' in componentSetting.controllerData) {
|
||||||
componentSetting.controllerData.value = value
|
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) {
|
} else if ('input' === componentSetting.controllerType) {
|
||||||
const value = settings[key as keyof ModelParams] as string
|
const value = settings[key as keyof ModelParams] as string
|
||||||
const placeholder = settings[key as keyof ModelParams] as string
|
const placeholder = settings[key as keyof ModelParams] as string
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user