diff --git a/joi/src/core/Slider/index.tsx b/joi/src/core/Slider/index.tsx index 40e0c39773..7f8c6cb895 100644 --- a/joi/src/core/Slider/index.tsx +++ b/joi/src/core/Slider/index.tsx @@ -1,5 +1,6 @@ import React from 'react' import * as SliderPrimitive from '@radix-ui/react-slider' +import { twMerge } from 'tailwind-merge' import './styles.scss' @@ -25,7 +26,7 @@ const Slider = ({ disabled, }: Props) => ( (false) + +export const LocalAPIserverModelParamsAtom = atom() diff --git a/web/screens/LocalServer/LocalServerLeftPanel/index.tsx b/web/screens/LocalServer/LocalServerLeftPanel/index.tsx index 91e00b430c..010566f518 100644 --- a/web/screens/LocalServer/LocalServerLeftPanel/index.tsx +++ b/web/screens/LocalServer/LocalServerLeftPanel/index.tsx @@ -1,5 +1,6 @@ import { Fragment, useCallback, useState } from 'react' +import { EngineManager, Model, ModelSettingParams } from '@janhq/core' import { Button, Tooltip, Select, Input, Checkbox } from '@janhq/joi' import { useAtom, useAtomValue, useSetAtom } from 'jotai' @@ -22,7 +23,10 @@ import { hostOptions, } 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' const LocalServerLeftPanel = () => { @@ -31,7 +35,7 @@ const LocalServerLeftPanel = () => { const [serverEnabled, setServerEnabled] = useAtom(serverEnabledAtom) const [isLoading, setIsLoading] = useState(false) - const { startModel, stateModel } = useActiveModel() + const { stateModel } = useActiveModel() const selectedModel = useAtomValue(selectedModelAtom) const [isCorsEnabled, setIsCorsEnabled] = useAtom(apiServerCorsEnabledAtom) @@ -42,9 +46,19 @@ const LocalServerLeftPanel = () => { const [port, setPort] = useAtom(apiServerPortAtom) const [prefix, setPrefix] = useAtom(apiServerPrefix) const setLoadModelError = useSetAtom(loadModelErrorAtom) - + const localAPIserverModelParams = useAtomValue(LocalAPIserverModelParamsAtom) 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] = useState(false) @@ -80,7 +94,9 @@ const LocalServerLeftPanel = () => { localStorage.setItem(FIRST_TIME_VISIT_API_SERVER, '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) } catch (e) { console.error(e) diff --git a/web/screens/LocalServer/LocalServerRightPanel/index.tsx b/web/screens/LocalServer/LocalServerRightPanel/index.tsx index f0a11a8657..5dba251dfa 100644 --- a/web/screens/LocalServer/LocalServerRightPanel/index.tsx +++ b/web/screens/LocalServer/LocalServerRightPanel/index.tsx @@ -17,13 +17,15 @@ import { useClipboard } from '@/hooks/useClipboard' 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 { getActiveThreadModelParamsAtom } from '@/helpers/atoms/Thread.atom' const LocalServerRightPanel = () => { - const activeModelParams = useAtomValue(getActiveThreadModelParamsAtom) const loadModelError = useAtomValue(loadModelErrorAtom) + const setLocalAPIserverModelParams = useSetAtom(LocalAPIserverModelParamsAtom) const serverEnabled = useAtomValue(serverEnabledAtom) const setModalTroubleShooting = useSetAtom(modalTroubleShootingAtom) @@ -35,12 +37,19 @@ const LocalServerRightPanel = () => { extractModelLoadParams(selectedModel?.settings) ) + const overriddenSettings = + selectedModel?.settings.ctx_len && selectedModel.settings.ctx_len > 2048 + ? { ctx_len: 4096 } + : {} + useEffect(() => { if (selectedModel) { - setCurrentModelSettingParams( - extractModelLoadParams(selectedModel?.settings) - ) + setCurrentModelSettingParams({ + ...selectedModel?.settings, + ...overriddenSettings, + }) } + // eslint-disable-next-line react-hooks/exhaustive-deps }, [selectedModel]) const modelRuntimeParams = extractInferenceParams(selectedModel?.settings) @@ -50,17 +59,8 @@ const LocalServerRightPanel = () => { selectedModel ) - const modelEngineParams = extractModelLoadParams( - { - ...selectedModel?.settings, - ...activeModelParams, - }, - selectedModel?.settings - ) - const componentDataEngineSetting = getConfigurationsData( - modelEngineParams, - selectedModel + currentModelSettingParams ) const engineSettings = useMemo( @@ -78,16 +78,27 @@ const LocalServerRightPanel = () => { ) }, [componentDataRuntimeSetting]) + const onUpdateParams = useCallback(() => { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + setLocalAPIserverModelParams(() => { + return { ...currentModelSettingParams } + }) + }, [currentModelSettingParams, setLocalAPIserverModelParams]) + const onValueChanged = useCallback( (key: string, value: string | number | boolean) => { - setCurrentModelSettingParams({ - ...currentModelSettingParams, + setCurrentModelSettingParams((prevParams) => ({ + ...prevParams, [key]: value, - }) + })) }, - [currentModelSettingParams] + [] ) + useEffect(() => { + onUpdateParams() + }, [currentModelSettingParams, onUpdateParams]) + return (
@@ -156,6 +167,7 @@ const LocalServerRightPanel = () => { )} @@ -165,6 +177,7 @@ const LocalServerRightPanel = () => { )}