forked from janhq/jan
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: not able to update model setting in local api (janhq#2687)
Signed-off-by: James <[email protected]> Co-authored-by: James <[email protected]>
- Loading branch information
Showing
8 changed files
with
102 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,23 @@ | ||
import { useCallback } from 'react' | ||
|
||
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 { serverEnabledAtom } from '@/helpers/atoms/LocalServer.atom' | ||
import { | ||
activeThreadAtom, | ||
engineParamsUpdateAtom, | ||
} from '@/helpers/atoms/Thread.atom' | ||
|
||
type Props = { | ||
componentData: SettingComponentProps[] | ||
onValueChanged: (key: string, value: string | number | boolean) => void | ||
disabled?: boolean | ||
} | ||
|
||
const EngineSetting: React.FC<Props> = ({ componentData }) => { | ||
const isLocalServerRunning = useAtomValue(serverEnabledAtom) | ||
const activeThread = useAtomValue(activeThreadAtom) | ||
|
||
const { stopModel } = useActiveModel() | ||
const { updateModelParameter } = useUpdateModelParameters() | ||
|
||
const setEngineParamsUpdate = useSetAtom(engineParamsUpdateAtom) | ||
|
||
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} | ||
/> | ||
) | ||
} | ||
const EngineSetting: React.FC<Props> = ({ | ||
componentData, | ||
onValueChanged, | ||
disabled = false, | ||
}) => ( | ||
<SettingComponentBuilder | ||
componentProps={componentData} | ||
disabled={disabled} | ||
onValueUpdated={onValueChanged} | ||
/> | ||
) | ||
|
||
export default EngineSetting |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,25 @@ | ||
import React, { useCallback } from 'react' | ||
import React from 'react' | ||
|
||
import { SettingComponentProps } from '@janhq/core/.' | ||
|
||
import { useAtomValue } from 'jotai' | ||
|
||
import useUpdateModelParameters from '@/hooks/useUpdateModelParameters' | ||
|
||
import SettingComponentBuilder from './SettingComponent' | ||
|
||
import { serverEnabledAtom } from '@/helpers/atoms/LocalServer.atom' | ||
import { activeThreadAtom } from '@/helpers/atoms/Thread.atom' | ||
|
||
type Props = { | ||
componentProps: SettingComponentProps[] | ||
onValueChanged: (key: string, value: string | number | boolean) => void | ||
disabled?: boolean | ||
} | ||
|
||
const ModelSetting: React.FC<Props> = ({ componentProps }) => { | ||
const isLocalServerRunning = useAtomValue(serverEnabledAtom) | ||
const activeThread = useAtomValue(activeThreadAtom) | ||
const { updateModelParameter } = useUpdateModelParameters() | ||
|
||
const onValueChanged = useCallback( | ||
(key: string, value: string | number | boolean) => { | ||
if (!activeThread) return | ||
|
||
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} | ||
/> | ||
) | ||
} | ||
const ModelSetting: React.FC<Props> = ({ | ||
componentProps, | ||
onValueChanged, | ||
disabled = false, | ||
}) => ( | ||
<SettingComponentBuilder | ||
disabled={!disabled} | ||
componentProps={componentProps} | ||
onValueUpdated={onValueChanged} | ||
/> | ||
) | ||
|
||
export default React.memo(ModelSetting) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.