fix: not able to update model setting in local api (#2687)
Signed-off-by: James <james@jan.ai> Co-authored-by: James <james@jan.ai>
This commit is contained in:
parent
02c49e796d
commit
3deaa8f7ee
@ -14,7 +14,7 @@ import { InfoIcon } from 'lucide-react'
|
|||||||
type Props = {
|
type Props = {
|
||||||
name: string
|
name: string
|
||||||
title: string
|
title: string
|
||||||
enabled?: boolean
|
disabled?: boolean
|
||||||
description: string
|
description: string
|
||||||
checked: boolean
|
checked: boolean
|
||||||
onValueChanged?: (e: string | number | boolean) => void
|
onValueChanged?: (e: string | number | boolean) => void
|
||||||
@ -23,7 +23,7 @@ type Props = {
|
|||||||
const Checkbox: React.FC<Props> = ({
|
const Checkbox: React.FC<Props> = ({
|
||||||
title,
|
title,
|
||||||
checked,
|
checked,
|
||||||
enabled = true,
|
disabled = false,
|
||||||
description,
|
description,
|
||||||
onValueChanged,
|
onValueChanged,
|
||||||
}) => {
|
}) => {
|
||||||
@ -52,7 +52,7 @@ const Checkbox: React.FC<Props> = ({
|
|||||||
<Switch
|
<Switch
|
||||||
checked={checked}
|
checked={checked}
|
||||||
onCheckedChange={onCheckedChange}
|
onCheckedChange={onCheckedChange}
|
||||||
disabled={!enabled}
|
disabled={disabled}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
@ -11,7 +11,7 @@ import { InfoIcon } from 'lucide-react'
|
|||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
title: string
|
title: string
|
||||||
enabled?: boolean
|
disabled?: boolean
|
||||||
name: string
|
name: string
|
||||||
description: string
|
description: string
|
||||||
placeholder: string
|
placeholder: string
|
||||||
@ -21,7 +21,7 @@ type Props = {
|
|||||||
|
|
||||||
const ModelConfigInput: React.FC<Props> = ({
|
const ModelConfigInput: React.FC<Props> = ({
|
||||||
title,
|
title,
|
||||||
enabled = true,
|
disabled = false,
|
||||||
value,
|
value,
|
||||||
description,
|
description,
|
||||||
placeholder,
|
placeholder,
|
||||||
@ -48,7 +48,7 @@ const ModelConfigInput: React.FC<Props> = ({
|
|||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
onChange={(e) => onValueChanged?.(e.target.value)}
|
onChange={(e) => onValueChanged?.(e.target.value)}
|
||||||
value={value}
|
value={value}
|
||||||
disabled={!enabled}
|
disabled={disabled}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
@ -17,7 +17,7 @@ import { useClickOutside } from '@/hooks/useClickOutside'
|
|||||||
type Props = {
|
type Props = {
|
||||||
name: string
|
name: string
|
||||||
title: string
|
title: string
|
||||||
enabled: boolean
|
disabled: boolean
|
||||||
description: string
|
description: string
|
||||||
min: number
|
min: number
|
||||||
max: number
|
max: number
|
||||||
@ -28,7 +28,7 @@ type Props = {
|
|||||||
|
|
||||||
const SliderRightPanel: React.FC<Props> = ({
|
const SliderRightPanel: React.FC<Props> = ({
|
||||||
title,
|
title,
|
||||||
enabled,
|
disabled,
|
||||||
min,
|
min,
|
||||||
max,
|
max,
|
||||||
step,
|
step,
|
||||||
@ -65,7 +65,7 @@ const SliderRightPanel: React.FC<Props> = ({
|
|||||||
min={min}
|
min={min}
|
||||||
max={max}
|
max={max}
|
||||||
step={step}
|
step={step}
|
||||||
disabled={!enabled}
|
disabled={disabled}
|
||||||
/>
|
/>
|
||||||
<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>
|
||||||
@ -80,7 +80,7 @@ const SliderRightPanel: React.FC<Props> = ({
|
|||||||
min={min}
|
min={min}
|
||||||
max={max}
|
max={max}
|
||||||
value={String(value)}
|
value={String(value)}
|
||||||
disabled={!enabled}
|
disabled={disabled}
|
||||||
onBlur={(e) => {
|
onBlur={(e) => {
|
||||||
if (Number(e.target.value) > Number(max)) {
|
if (Number(e.target.value) > Number(max)) {
|
||||||
onValueChanged?.(Number(max))
|
onValueChanged?.(Number(max))
|
||||||
|
|||||||
@ -1,54 +1,23 @@
|
|||||||
import { useCallback } from 'react'
|
|
||||||
|
|
||||||
import { SettingComponentProps } from '@janhq/core/.'
|
import { SettingComponentProps } from '@janhq/core/.'
|
||||||
|
|
||||||
import { useAtomValue, useSetAtom } from 'jotai'
|
|
||||||
|
|
||||||
import { useActiveModel } from '@/hooks/useActiveModel'
|
|
||||||
import useUpdateModelParameters from '@/hooks/useUpdateModelParameters'
|
|
||||||
|
|
||||||
import SettingComponentBuilder from '../../Chat/ModelSetting/SettingComponent'
|
import SettingComponentBuilder from '../../Chat/ModelSetting/SettingComponent'
|
||||||
|
|
||||||
import { serverEnabledAtom } from '@/helpers/atoms/LocalServer.atom'
|
|
||||||
import {
|
|
||||||
activeThreadAtom,
|
|
||||||
engineParamsUpdateAtom,
|
|
||||||
} from '@/helpers/atoms/Thread.atom'
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
componentData: SettingComponentProps[]
|
componentData: SettingComponentProps[]
|
||||||
|
onValueChanged: (key: string, value: string | number | boolean) => void
|
||||||
|
disabled?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const EngineSetting: React.FC<Props> = ({ componentData }) => {
|
const EngineSetting: React.FC<Props> = ({
|
||||||
const isLocalServerRunning = useAtomValue(serverEnabledAtom)
|
componentData,
|
||||||
const activeThread = useAtomValue(activeThreadAtom)
|
onValueChanged,
|
||||||
|
disabled = false,
|
||||||
const { stopModel } = useActiveModel()
|
}) => (
|
||||||
const { updateModelParameter } = useUpdateModelParameters()
|
<SettingComponentBuilder
|
||||||
|
componentProps={componentData}
|
||||||
const setEngineParamsUpdate = useSetAtom(engineParamsUpdateAtom)
|
disabled={disabled}
|
||||||
|
onValueUpdated={onValueChanged}
|
||||||
const onValueChanged = useCallback(
|
/>
|
||||||
(key: string, value: string | number | boolean) => {
|
)
|
||||||
if (!activeThread) return
|
|
||||||
|
|
||||||
setEngineParamsUpdate(true)
|
|
||||||
stopModel()
|
|
||||||
|
|
||||||
updateModelParameter(activeThread, {
|
|
||||||
params: { [key]: value },
|
|
||||||
})
|
|
||||||
},
|
|
||||||
[activeThread, setEngineParamsUpdate, stopModel, updateModelParameter]
|
|
||||||
)
|
|
||||||
|
|
||||||
return (
|
|
||||||
<SettingComponentBuilder
|
|
||||||
componentProps={componentData}
|
|
||||||
enabled={!isLocalServerRunning}
|
|
||||||
onValueUpdated={onValueChanged}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export default EngineSetting
|
export default EngineSetting
|
||||||
|
|||||||
@ -11,13 +11,13 @@ import SliderRightPanel from '@/containers/SliderRightPanel'
|
|||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
componentProps: SettingComponentProps[]
|
componentProps: SettingComponentProps[]
|
||||||
enabled?: boolean
|
disabled?: boolean
|
||||||
onValueUpdated: (key: string, value: string | number | boolean) => void
|
onValueUpdated: (key: string, value: string | number | boolean) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const SettingComponent: React.FC<Props> = ({
|
const SettingComponent: React.FC<Props> = ({
|
||||||
componentProps,
|
componentProps,
|
||||||
enabled = true,
|
disabled = false,
|
||||||
onValueUpdated,
|
onValueUpdated,
|
||||||
}) => {
|
}) => {
|
||||||
const components = componentProps.map((data) => {
|
const components = componentProps.map((data) => {
|
||||||
@ -35,7 +35,7 @@ const SettingComponent: React.FC<Props> = ({
|
|||||||
step={step}
|
step={step}
|
||||||
value={value}
|
value={value}
|
||||||
name={data.key}
|
name={data.key}
|
||||||
enabled={enabled}
|
disabled={disabled}
|
||||||
onValueChanged={(value) => onValueUpdated(data.key, value)}
|
onValueChanged={(value) => onValueUpdated(data.key, value)}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
@ -47,7 +47,7 @@ const SettingComponent: React.FC<Props> = ({
|
|||||||
return (
|
return (
|
||||||
<ModelConfigInput
|
<ModelConfigInput
|
||||||
title={data.title}
|
title={data.title}
|
||||||
enabled={enabled}
|
disabled={disabled}
|
||||||
key={data.key}
|
key={data.key}
|
||||||
name={data.key}
|
name={data.key}
|
||||||
description={data.description}
|
description={data.description}
|
||||||
@ -63,7 +63,7 @@ const SettingComponent: React.FC<Props> = ({
|
|||||||
return (
|
return (
|
||||||
<Checkbox
|
<Checkbox
|
||||||
key={data.key}
|
key={data.key}
|
||||||
enabled={enabled}
|
disabled={disabled}
|
||||||
name={data.key}
|
name={data.key}
|
||||||
description={data.description}
|
description={data.description}
|
||||||
title={data.title}
|
title={data.title}
|
||||||
|
|||||||
@ -1,49 +1,25 @@
|
|||||||
import React, { useCallback } from 'react'
|
import React from 'react'
|
||||||
|
|
||||||
import { SettingComponentProps } from '@janhq/core/.'
|
import { SettingComponentProps } from '@janhq/core/.'
|
||||||
|
|
||||||
import { useAtomValue } from 'jotai'
|
|
||||||
|
|
||||||
import useUpdateModelParameters from '@/hooks/useUpdateModelParameters'
|
|
||||||
|
|
||||||
import SettingComponentBuilder from './SettingComponent'
|
import SettingComponentBuilder from './SettingComponent'
|
||||||
|
|
||||||
import { serverEnabledAtom } from '@/helpers/atoms/LocalServer.atom'
|
|
||||||
import { activeThreadAtom } from '@/helpers/atoms/Thread.atom'
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
componentProps: SettingComponentProps[]
|
componentProps: SettingComponentProps[]
|
||||||
|
onValueChanged: (key: string, value: string | number | boolean) => void
|
||||||
|
disabled?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const ModelSetting: React.FC<Props> = ({ componentProps }) => {
|
const ModelSetting: React.FC<Props> = ({
|
||||||
const isLocalServerRunning = useAtomValue(serverEnabledAtom)
|
componentProps,
|
||||||
const activeThread = useAtomValue(activeThreadAtom)
|
onValueChanged,
|
||||||
const { updateModelParameter } = useUpdateModelParameters()
|
disabled = false,
|
||||||
|
}) => (
|
||||||
const onValueChanged = useCallback(
|
<SettingComponentBuilder
|
||||||
(key: string, value: string | number | boolean) => {
|
disabled={!disabled}
|
||||||
if (!activeThread) return
|
componentProps={componentProps}
|
||||||
|
onValueUpdated={onValueChanged}
|
||||||
if (key === 'stop' && typeof value === 'string') {
|
/>
|
||||||
updateModelParameter(activeThread, {
|
)
|
||||||
params: { [key]: [value] },
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
updateModelParameter(activeThread, {
|
|
||||||
params: { [key]: value },
|
|
||||||
})
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[activeThread, updateModelParameter]
|
|
||||||
)
|
|
||||||
|
|
||||||
return (
|
|
||||||
<SettingComponentBuilder
|
|
||||||
enabled={!isLocalServerRunning}
|
|
||||||
componentProps={componentProps}
|
|
||||||
onValueUpdated={onValueChanged}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export default React.memo(ModelSetting)
|
export default React.memo(ModelSetting)
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import React, { useCallback, useMemo } from 'react'
|
|||||||
|
|
||||||
import { Input, Textarea } from '@janhq/uikit'
|
import { Input, Textarea } from '@janhq/uikit'
|
||||||
|
|
||||||
import { atom, useAtomValue } from 'jotai'
|
import { atom, useAtomValue, useSetAtom } from 'jotai'
|
||||||
|
|
||||||
import { twMerge } from 'tailwind-merge'
|
import { twMerge } from 'tailwind-merge'
|
||||||
|
|
||||||
@ -13,8 +13,11 @@ import DropdownListSidebar, {
|
|||||||
selectedModelAtom,
|
selectedModelAtom,
|
||||||
} from '@/containers/DropdownListSidebar'
|
} from '@/containers/DropdownListSidebar'
|
||||||
|
|
||||||
|
import { useActiveModel } from '@/hooks/useActiveModel'
|
||||||
import { useCreateNewThread } from '@/hooks/useCreateNewThread'
|
import { useCreateNewThread } from '@/hooks/useCreateNewThread'
|
||||||
|
|
||||||
|
import useUpdateModelParameters from '@/hooks/useUpdateModelParameters'
|
||||||
|
|
||||||
import { getConfigurationsData } from '@/utils/componentSettings'
|
import { getConfigurationsData } from '@/utils/componentSettings'
|
||||||
import { toRuntimeParams, toSettingParams } from '@/utils/modelParam'
|
import { toRuntimeParams, toSettingParams } from '@/utils/modelParam'
|
||||||
|
|
||||||
@ -27,6 +30,7 @@ import PromptTemplateSetting from './PromptTemplateSetting'
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
activeThreadAtom,
|
activeThreadAtom,
|
||||||
|
engineParamsUpdateAtom,
|
||||||
getActiveThreadModelParamsAtom,
|
getActiveThreadModelParamsAtom,
|
||||||
} from '@/helpers/atoms/Thread.atom'
|
} from '@/helpers/atoms/Thread.atom'
|
||||||
|
|
||||||
@ -39,6 +43,10 @@ const Sidebar: React.FC = () => {
|
|||||||
const selectedModel = useAtomValue(selectedModelAtom)
|
const selectedModel = useAtomValue(selectedModelAtom)
|
||||||
const { updateThreadMetadata } = useCreateNewThread()
|
const { updateThreadMetadata } = useCreateNewThread()
|
||||||
|
|
||||||
|
const setEngineParamsUpdate = useSetAtom(engineParamsUpdateAtom)
|
||||||
|
const { stopModel } = useActiveModel()
|
||||||
|
const { updateModelParameter } = useUpdateModelParameters()
|
||||||
|
|
||||||
const modelSettings = useMemo(() => {
|
const modelSettings = useMemo(() => {
|
||||||
const modelRuntimeParams = toRuntimeParams(activeModelParams)
|
const modelRuntimeParams = toRuntimeParams(activeModelParams)
|
||||||
|
|
||||||
@ -96,6 +104,22 @@ const Sidebar: React.FC = () => {
|
|||||||
[activeThread, updateThreadMetadata]
|
[activeThread, updateThreadMetadata]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const onValueChanged = useCallback(
|
||||||
|
(key: string, value: string | number | boolean) => {
|
||||||
|
if (!activeThread) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
setEngineParamsUpdate(true)
|
||||||
|
stopModel()
|
||||||
|
|
||||||
|
updateModelParameter(activeThread, {
|
||||||
|
params: { [key]: value },
|
||||||
|
})
|
||||||
|
},
|
||||||
|
[activeThread, setEngineParamsUpdate, stopModel, updateModelParameter]
|
||||||
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={twMerge(
|
className={twMerge(
|
||||||
@ -170,7 +194,10 @@ const Sidebar: React.FC = () => {
|
|||||||
{modelSettings.length > 0 && (
|
{modelSettings.length > 0 && (
|
||||||
<CardSidebar title="Inference Parameters" asChild>
|
<CardSidebar title="Inference Parameters" asChild>
|
||||||
<div className="px-2 py-4">
|
<div className="px-2 py-4">
|
||||||
<ModelSetting componentProps={modelSettings} />
|
<ModelSetting
|
||||||
|
componentProps={modelSettings}
|
||||||
|
onValueChanged={onValueChanged}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</CardSidebar>
|
</CardSidebar>
|
||||||
)}
|
)}
|
||||||
@ -188,7 +215,10 @@ const Sidebar: React.FC = () => {
|
|||||||
{engineSettings.length > 0 && (
|
{engineSettings.length > 0 && (
|
||||||
<CardSidebar title="Engine Parameters" asChild>
|
<CardSidebar title="Engine Parameters" asChild>
|
||||||
<div className="px-2 py-4">
|
<div className="px-2 py-4">
|
||||||
<EngineSetting componentData={engineSettings} />
|
<EngineSetting
|
||||||
|
componentData={engineSettings}
|
||||||
|
onValueChanged={onValueChanged}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</CardSidebar>
|
</CardSidebar>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@ -73,10 +73,15 @@ const LocalServerScreen = () => {
|
|||||||
const { startModel, stateModel } = useActiveModel()
|
const { startModel, stateModel } = useActiveModel()
|
||||||
const selectedModel = useAtomValue(selectedModelAtom)
|
const selectedModel = useAtomValue(selectedModelAtom)
|
||||||
|
|
||||||
const modelEngineParams = toSettingParams(selectedModel?.settings)
|
|
||||||
const modelRuntimeParams = toRuntimeParams(selectedModel?.settings)
|
const modelRuntimeParams = toRuntimeParams(selectedModel?.settings)
|
||||||
|
|
||||||
const componentDataEngineSetting = getConfigurationsData(modelEngineParams)
|
const [currentModelSettingParams, setCurrentModelSettingParams] = useState(
|
||||||
|
toSettingParams(selectedModel?.settings)
|
||||||
|
)
|
||||||
|
|
||||||
|
const componentDataEngineSetting = getConfigurationsData(
|
||||||
|
currentModelSettingParams
|
||||||
|
)
|
||||||
const componentDataRuntimeSetting = getConfigurationsData(
|
const componentDataRuntimeSetting = getConfigurationsData(
|
||||||
modelRuntimeParams,
|
modelRuntimeParams,
|
||||||
selectedModel
|
selectedModel
|
||||||
@ -177,6 +182,16 @@ const LocalServerScreen = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const onValueChanged = useCallback(
|
||||||
|
(key: string, value: string | number | boolean) => {
|
||||||
|
setCurrentModelSettingParams({
|
||||||
|
...currentModelSettingParams,
|
||||||
|
[key]: value,
|
||||||
|
})
|
||||||
|
},
|
||||||
|
[currentModelSettingParams]
|
||||||
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex h-full w-full" data-testid="local-server-testid">
|
<div className="flex h-full w-full" data-testid="local-server-testid">
|
||||||
{/* Left SideBar */}
|
{/* Left SideBar */}
|
||||||
@ -495,7 +510,11 @@ const LocalServerScreen = () => {
|
|||||||
<div className="mt-4">
|
<div className="mt-4">
|
||||||
<CardSidebar title="Model Parameters" asChild>
|
<CardSidebar title="Model Parameters" asChild>
|
||||||
<div className="px-2 py-4">
|
<div className="px-2 py-4">
|
||||||
<ModelSetting componentProps={modelSettings} />
|
<ModelSetting
|
||||||
|
componentProps={modelSettings}
|
||||||
|
disabled={serverEnabled}
|
||||||
|
onValueChanged={onValueChanged}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</CardSidebar>
|
</CardSidebar>
|
||||||
</div>
|
</div>
|
||||||
@ -505,7 +524,11 @@ const LocalServerScreen = () => {
|
|||||||
<div className="my-4">
|
<div className="my-4">
|
||||||
<CardSidebar title="Engine Parameters" asChild>
|
<CardSidebar title="Engine Parameters" asChild>
|
||||||
<div className="px-2 py-4">
|
<div className="px-2 py-4">
|
||||||
<EngineSetting componentData={engineSettings} />
|
<EngineSetting
|
||||||
|
disabled={serverEnabled}
|
||||||
|
componentData={engineSettings}
|
||||||
|
onValueChanged={onValueChanged}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</CardSidebar>
|
</CardSidebar>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user