fix: model params settings local api server (#4077)
* fix: model params local api server * chore: fix linter
This commit is contained in:
parent
e9de9e728d
commit
28e32df318
@ -1,5 +1,6 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import * as SliderPrimitive from '@radix-ui/react-slider'
|
import * as SliderPrimitive from '@radix-ui/react-slider'
|
||||||
|
import { twMerge } from 'tailwind-merge'
|
||||||
|
|
||||||
import './styles.scss'
|
import './styles.scss'
|
||||||
|
|
||||||
@ -25,7 +26,7 @@ const Slider = ({
|
|||||||
disabled,
|
disabled,
|
||||||
}: Props) => (
|
}: Props) => (
|
||||||
<SliderPrimitive.Root
|
<SliderPrimitive.Root
|
||||||
className="slider"
|
className={twMerge('slider', disabled && 'slider--disabled')}
|
||||||
name={name}
|
name={name}
|
||||||
min={min}
|
min={min}
|
||||||
max={max}
|
max={max}
|
||||||
|
|||||||
@ -6,6 +6,11 @@
|
|||||||
touch-action: none;
|
touch-action: none;
|
||||||
height: 16px;
|
height: 16px;
|
||||||
|
|
||||||
|
&--disabled {
|
||||||
|
cursor: not-allowed;
|
||||||
|
opacity: 0.2;
|
||||||
|
}
|
||||||
|
|
||||||
&__track {
|
&__track {
|
||||||
background-color: hsla(var(--slider-track-bg));
|
background-color: hsla(var(--slider-track-bg));
|
||||||
position: relative;
|
position: relative;
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
import { atom } from 'jotai'
|
import { atom } from 'jotai'
|
||||||
|
|
||||||
export const serverEnabledAtom = atom<boolean>(false)
|
export const serverEnabledAtom = atom<boolean>(false)
|
||||||
|
|
||||||
|
export const LocalAPIserverModelParamsAtom = atom()
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import { Fragment, useCallback, useState } from 'react'
|
import { Fragment, useCallback, useState } from 'react'
|
||||||
|
|
||||||
|
import { EngineManager, Model, ModelSettingParams } from '@janhq/core'
|
||||||
import { Button, Tooltip, Select, Input, Checkbox } from '@janhq/joi'
|
import { Button, Tooltip, Select, Input, Checkbox } from '@janhq/joi'
|
||||||
|
|
||||||
import { useAtom, useAtomValue, useSetAtom } from 'jotai'
|
import { useAtom, useAtomValue, useSetAtom } from 'jotai'
|
||||||
@ -22,7 +23,10 @@ import {
|
|||||||
hostOptions,
|
hostOptions,
|
||||||
} from '@/helpers/atoms/ApiServer.atom'
|
} from '@/helpers/atoms/ApiServer.atom'
|
||||||
|
|
||||||
import { serverEnabledAtom } from '@/helpers/atoms/LocalServer.atom'
|
import {
|
||||||
|
LocalAPIserverModelParamsAtom,
|
||||||
|
serverEnabledAtom,
|
||||||
|
} from '@/helpers/atoms/LocalServer.atom'
|
||||||
import { selectedModelAtom } from '@/helpers/atoms/Model.atom'
|
import { selectedModelAtom } from '@/helpers/atoms/Model.atom'
|
||||||
|
|
||||||
const LocalServerLeftPanel = () => {
|
const LocalServerLeftPanel = () => {
|
||||||
@ -31,7 +35,7 @@ const LocalServerLeftPanel = () => {
|
|||||||
const [serverEnabled, setServerEnabled] = useAtom(serverEnabledAtom)
|
const [serverEnabled, setServerEnabled] = useAtom(serverEnabledAtom)
|
||||||
const [isLoading, setIsLoading] = useState(false)
|
const [isLoading, setIsLoading] = useState(false)
|
||||||
|
|
||||||
const { startModel, stateModel } = useActiveModel()
|
const { stateModel } = useActiveModel()
|
||||||
const selectedModel = useAtomValue(selectedModelAtom)
|
const selectedModel = useAtomValue(selectedModelAtom)
|
||||||
|
|
||||||
const [isCorsEnabled, setIsCorsEnabled] = useAtom(apiServerCorsEnabledAtom)
|
const [isCorsEnabled, setIsCorsEnabled] = useAtom(apiServerCorsEnabledAtom)
|
||||||
@ -42,9 +46,19 @@ const LocalServerLeftPanel = () => {
|
|||||||
const [port, setPort] = useAtom(apiServerPortAtom)
|
const [port, setPort] = useAtom(apiServerPortAtom)
|
||||||
const [prefix, setPrefix] = useAtom(apiServerPrefix)
|
const [prefix, setPrefix] = useAtom(apiServerPrefix)
|
||||||
const setLoadModelError = useSetAtom(loadModelErrorAtom)
|
const setLoadModelError = useSetAtom(loadModelErrorAtom)
|
||||||
|
const localAPIserverModelParams = useAtomValue(LocalAPIserverModelParamsAtom)
|
||||||
const FIRST_TIME_VISIT_API_SERVER = 'firstTimeVisitAPIServer'
|
const FIRST_TIME_VISIT_API_SERVER = 'firstTimeVisitAPIServer'
|
||||||
|
|
||||||
|
const model: Model | undefined = selectedModel
|
||||||
|
? {
|
||||||
|
...selectedModel,
|
||||||
|
object: selectedModel.object || '',
|
||||||
|
settings: (typeof localAPIserverModelParams === 'object'
|
||||||
|
? { ...(localAPIserverModelParams as ModelSettingParams) }
|
||||||
|
: { ...selectedModel.settings }) as ModelSettingParams,
|
||||||
|
}
|
||||||
|
: undefined
|
||||||
|
|
||||||
const [firstTimeVisitAPIServer, setFirstTimeVisitAPIServer] =
|
const [firstTimeVisitAPIServer, setFirstTimeVisitAPIServer] =
|
||||||
useState<boolean>(false)
|
useState<boolean>(false)
|
||||||
|
|
||||||
@ -80,7 +94,9 @@ const LocalServerLeftPanel = () => {
|
|||||||
localStorage.setItem(FIRST_TIME_VISIT_API_SERVER, 'false')
|
localStorage.setItem(FIRST_TIME_VISIT_API_SERVER, 'false')
|
||||||
setFirstTimeVisitAPIServer(false)
|
setFirstTimeVisitAPIServer(false)
|
||||||
}
|
}
|
||||||
startModel(selectedModel.id, false).catch((e) => console.error(e))
|
const engine = EngineManager.instance().get((model as Model).engine)
|
||||||
|
engine?.loadModel(model as Model)
|
||||||
|
// startModel(selectedModel.id, false).catch((e) => console.error(e))
|
||||||
setIsLoading(false)
|
setIsLoading(false)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
|
|||||||
@ -17,13 +17,15 @@ import { useClipboard } from '@/hooks/useClipboard'
|
|||||||
|
|
||||||
import { getConfigurationsData } from '@/utils/componentSettings'
|
import { getConfigurationsData } from '@/utils/componentSettings'
|
||||||
|
|
||||||
import { serverEnabledAtom } from '@/helpers/atoms/LocalServer.atom'
|
import {
|
||||||
|
LocalAPIserverModelParamsAtom,
|
||||||
|
serverEnabledAtom,
|
||||||
|
} from '@/helpers/atoms/LocalServer.atom'
|
||||||
import { selectedModelAtom } from '@/helpers/atoms/Model.atom'
|
import { selectedModelAtom } from '@/helpers/atoms/Model.atom'
|
||||||
import { getActiveThreadModelParamsAtom } from '@/helpers/atoms/Thread.atom'
|
|
||||||
|
|
||||||
const LocalServerRightPanel = () => {
|
const LocalServerRightPanel = () => {
|
||||||
const activeModelParams = useAtomValue(getActiveThreadModelParamsAtom)
|
|
||||||
const loadModelError = useAtomValue(loadModelErrorAtom)
|
const loadModelError = useAtomValue(loadModelErrorAtom)
|
||||||
|
const setLocalAPIserverModelParams = useSetAtom(LocalAPIserverModelParamsAtom)
|
||||||
const serverEnabled = useAtomValue(serverEnabledAtom)
|
const serverEnabled = useAtomValue(serverEnabledAtom)
|
||||||
const setModalTroubleShooting = useSetAtom(modalTroubleShootingAtom)
|
const setModalTroubleShooting = useSetAtom(modalTroubleShootingAtom)
|
||||||
|
|
||||||
@ -35,12 +37,19 @@ const LocalServerRightPanel = () => {
|
|||||||
extractModelLoadParams(selectedModel?.settings)
|
extractModelLoadParams(selectedModel?.settings)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const overriddenSettings =
|
||||||
|
selectedModel?.settings.ctx_len && selectedModel.settings.ctx_len > 2048
|
||||||
|
? { ctx_len: 4096 }
|
||||||
|
: {}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (selectedModel) {
|
if (selectedModel) {
|
||||||
setCurrentModelSettingParams(
|
setCurrentModelSettingParams({
|
||||||
extractModelLoadParams(selectedModel?.settings)
|
...selectedModel?.settings,
|
||||||
)
|
...overriddenSettings,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [selectedModel])
|
}, [selectedModel])
|
||||||
|
|
||||||
const modelRuntimeParams = extractInferenceParams(selectedModel?.settings)
|
const modelRuntimeParams = extractInferenceParams(selectedModel?.settings)
|
||||||
@ -50,17 +59,8 @@ const LocalServerRightPanel = () => {
|
|||||||
selectedModel
|
selectedModel
|
||||||
)
|
)
|
||||||
|
|
||||||
const modelEngineParams = extractModelLoadParams(
|
|
||||||
{
|
|
||||||
...selectedModel?.settings,
|
|
||||||
...activeModelParams,
|
|
||||||
},
|
|
||||||
selectedModel?.settings
|
|
||||||
)
|
|
||||||
|
|
||||||
const componentDataEngineSetting = getConfigurationsData(
|
const componentDataEngineSetting = getConfigurationsData(
|
||||||
modelEngineParams,
|
currentModelSettingParams
|
||||||
selectedModel
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const engineSettings = useMemo(
|
const engineSettings = useMemo(
|
||||||
@ -78,16 +78,27 @@ const LocalServerRightPanel = () => {
|
|||||||
)
|
)
|
||||||
}, [componentDataRuntimeSetting])
|
}, [componentDataRuntimeSetting])
|
||||||
|
|
||||||
|
const onUpdateParams = useCallback(() => {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
setLocalAPIserverModelParams(() => {
|
||||||
|
return { ...currentModelSettingParams }
|
||||||
|
})
|
||||||
|
}, [currentModelSettingParams, setLocalAPIserverModelParams])
|
||||||
|
|
||||||
const onValueChanged = useCallback(
|
const onValueChanged = useCallback(
|
||||||
(key: string, value: string | number | boolean) => {
|
(key: string, value: string | number | boolean) => {
|
||||||
setCurrentModelSettingParams({
|
setCurrentModelSettingParams((prevParams) => ({
|
||||||
...currentModelSettingParams,
|
...prevParams,
|
||||||
[key]: value,
|
[key]: value,
|
||||||
})
|
}))
|
||||||
},
|
},
|
||||||
[currentModelSettingParams]
|
[]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
onUpdateParams()
|
||||||
|
}, [currentModelSettingParams, onUpdateParams])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<RightPanelContainer>
|
<RightPanelContainer>
|
||||||
<div className="mb-4 px-4 pt-4">
|
<div className="mb-4 px-4 pt-4">
|
||||||
@ -156,6 +167,7 @@ const LocalServerRightPanel = () => {
|
|||||||
<ModelSetting
|
<ModelSetting
|
||||||
componentProps={modelSettings}
|
componentProps={modelSettings}
|
||||||
onValueChanged={onValueChanged}
|
onValueChanged={onValueChanged}
|
||||||
|
disabled={serverEnabled}
|
||||||
/>
|
/>
|
||||||
</AccordionItem>
|
</AccordionItem>
|
||||||
)}
|
)}
|
||||||
@ -165,6 +177,7 @@ const LocalServerRightPanel = () => {
|
|||||||
<EngineSetting
|
<EngineSetting
|
||||||
componentData={engineSettings}
|
componentData={engineSettings}
|
||||||
onValueChanged={onValueChanged}
|
onValueChanged={onValueChanged}
|
||||||
|
disabled={serverEnabled}
|
||||||
/>
|
/>
|
||||||
</AccordionItem>
|
</AccordionItem>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user