Skip to content

Commit

Permalink
fix: could not change model params settings (janhq#1547)
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-jan authored Jan 12, 2024
1 parent 28c9a9c commit 7dec382
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
22 changes: 20 additions & 2 deletions web/containers/DropdownListSidebar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { useCallback, useEffect, useState } from 'react'

import { InferenceEngine, Model } from '@janhq/core'
import {
InferenceEngine,
Model,
ModelRuntimeParams,
ModelSettingParams,
} from '@janhq/core'
import {
Button,
Select,
Expand Down Expand Up @@ -29,6 +34,7 @@ import useRecommendedModel from '@/hooks/useRecommendedModel'
import { toGibibytes } from '@/utils/converter'

import {
ModelParams,
activeThreadAtom,
getActiveThreadIdAtom,
setThreadModelParamsAtom,
Expand Down Expand Up @@ -59,16 +65,28 @@ export default function DropdownListSidebar() {

const { recommendedModel, downloadedModels } = useRecommendedModel()

/**
* Default value for max_tokens and ctx_len
* Its to avoid OOM issue since a model can set a big number for these settings
*/
const defaultValue = (value?: number) => {
if (value && value < 4096) return value
return 4096
}

useEffect(() => {
setSelected(recommendedModel)
setSelectedModel(recommendedModel)

if (activeThread) {
const finishInit = threadStates[activeThread.id].isFinishInit ?? true
if (finishInit) return
const modelParams = {
const modelParams: ModelParams = {
...recommendedModel?.parameters,
...recommendedModel?.settings,
// This is to set default value for these settings instead of maximum value
max_tokens: defaultValue(recommendedModel?.parameters.max_tokens),
ctx_len: defaultValue(recommendedModel?.settings.ctx_len),
}
setThreadModelParams(activeThread.id, modelParams)
}
Expand Down
11 changes: 0 additions & 11 deletions web/utils/componentSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ export const getConfigurationsData = (
) => {
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]

Expand All @@ -32,16 +27,10 @@ export const getConfigurationsData = (
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
}
}
Expand Down

0 comments on commit 7dec382

Please sign in to comment.