-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Signed-off-by: James <[email protected]>
- Loading branch information
James
committed
Apr 11, 2024
1 parent
ebdaaa6
commit 60df366
Showing
7 changed files
with
79 additions
and
64 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
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