From b3b5c662984fa52f5017defb2fe84ae2fe68c6f2 Mon Sep 17 00:00:00 2001 From: Louis Date: Fri, 5 Apr 2024 15:24:17 +0700 Subject: [PATCH] chore: add GPU driver and toolkit status --- .../monitoring-extension/src/node/index.ts | 2 + web/containers/GPUDriverPromptModal/index.tsx | 79 ------------------- web/containers/Providers/index.tsx | 2 - web/hooks/useGetSystemResources.ts | 11 ++- web/hooks/useSettings.ts | 17 ---- web/screens/Settings/Advanced/index.tsx | 4 +- 6 files changed, 10 insertions(+), 105 deletions(-) delete mode 100644 web/containers/GPUDriverPromptModal/index.tsx diff --git a/extensions/monitoring-extension/src/node/index.ts b/extensions/monitoring-extension/src/node/index.ts index 17b56dbfde..194abcca2e 100644 --- a/extensions/monitoring-extension/src/node/index.ts +++ b/extensions/monitoring-extension/src/node/index.ts @@ -221,6 +221,7 @@ const updateGpuInfo = async () => data = updateCudaExistence(data) writeFileSync(GPU_INFO_FILE, JSON.stringify(data, null, 2)) + log(`[APP]::${JSON.stringify(data)}`) resolve({}) } else { reject(error) @@ -263,6 +264,7 @@ const updateGpuInfo = async () => data = updateCudaExistence(data) writeFileSync(GPU_INFO_FILE, JSON.stringify(data, null, 2)) + log(`[APP]::${JSON.stringify(data)}`) resolve({}) } ) diff --git a/web/containers/GPUDriverPromptModal/index.tsx b/web/containers/GPUDriverPromptModal/index.tsx deleted file mode 100644 index bdcf1b2f8f..0000000000 --- a/web/containers/GPUDriverPromptModal/index.tsx +++ /dev/null @@ -1,79 +0,0 @@ -import React from 'react' - -import { openExternalUrl } from '@janhq/core' - -import { - ModalClose, - ModalFooter, - ModalContent, - Modal, - ModalTitle, - ModalHeader, - Button, -} from '@janhq/uikit' - -import { useAtom } from 'jotai' - -import { isShowNotificationAtom, useSettings } from '@/hooks/useSettings' - -const GPUDriverPrompt: React.FC = () => { - const [showNotification, setShowNotification] = useAtom( - isShowNotificationAtom - ) - - const { saveSettings } = useSettings() - const onDoNotShowAgainChange = (e: React.ChangeEvent) => { - const isChecked = !e.target.checked - saveSettings({ notify: isChecked }) - } - - const openChanged = () => { - setShowNotification(false) - } - - return ( -
- - - - - Checking for machine that does not meet the requirements. - - -

- It appears that you are missing some dependencies required to run in - GPU mode. Please follow the instructions below for more details{' '} - - openExternalUrl( - 'https://jan.ai/guides/troubleshooting/gpu-not-used/' - ) - } - > - Jan is Not Using GPU - {' '} - . -

-
- - Don't show again -
- -
- - - -
-
-
-
-
- ) -} -export default GPUDriverPrompt diff --git a/web/containers/Providers/index.tsx b/web/containers/Providers/index.tsx index 999979758d..66ba42a7da 100644 --- a/web/containers/Providers/index.tsx +++ b/web/containers/Providers/index.tsx @@ -6,7 +6,6 @@ import { Toaster } from 'react-hot-toast' import { TooltipProvider } from '@janhq/uikit' -import GPUDriverPrompt from '@/containers/GPUDriverPromptModal' import EventListenerWrapper from '@/containers/Providers/EventListener' import JotaiWrapper from '@/containers/Providers/Jotai' import ThemeWrapper from '@/containers/Providers/Theme' @@ -81,7 +80,6 @@ const Providers = ({ children }: PropsWithChildren) => { {children} - {!isMac && } diff --git a/web/hooks/useGetSystemResources.ts b/web/hooks/useGetSystemResources.ts index 877b652cb5..8ee13257aa 100644 --- a/web/hooks/useGetSystemResources.ts +++ b/web/hooks/useGetSystemResources.ts @@ -1,8 +1,8 @@ import { useCallback, useEffect, useState } from 'react' -import { ExtensionTypeEnum, MonitoringExtension } from '@janhq/core' +import { ExtensionTypeEnum, log, MonitoringExtension } from '@janhq/core' -import { useSetAtom } from 'jotai' +import { useAtom, useSetAtom } from 'jotai' import { extensionManager } from '@/extension/ExtensionManager' import { @@ -21,7 +21,7 @@ export default function useGetSystemResources() { >(undefined) const setTotalRam = useSetAtom(totalRamAtom) - const setGpus = useSetAtom(gpusAtom) + const [gpus, setGpus] = useAtom(gpusAtom) const setUsedRam = useSetAtom(usedRamAtom) const setCpuUsage = useSetAtom(cpuUsageAtom) const setTotalNvidiaVram = useSetAtom(nvidiaTotalVramAtom) @@ -97,12 +97,15 @@ export default function useGetSystemResources() { }, [intervalId]) useEffect(() => { - getSystemResources() + getSystemResources().then( + () => gpus.length > 0 && log(`[APP]::${JSON.stringify(gpus)}`) + ) // Component did unmount // Stop watching if any return () => { stopWatching() } + // eslint-disable-next-line react-hooks/exhaustive-deps }, [getSystemResources, stopWatching]) return { diff --git a/web/hooks/useSettings.ts b/web/hooks/useSettings.ts index 9ff733f155..1930a10e05 100644 --- a/web/hooks/useSettings.ts +++ b/web/hooks/useSettings.ts @@ -1,9 +1,6 @@ import { useCallback, useEffect, useState } from 'react' import { fs, joinPath } from '@janhq/core' -import { atom, useAtom } from 'jotai' - -export const isShowNotificationAtom = atom(false) export type AppSettings = { run_mode: 'cpu' | 'gpu' | undefined @@ -15,9 +12,6 @@ export type AppSettings = { export const useSettings = () => { const [isGPUModeEnabled, setIsGPUModeEnabled] = useState(false) // New state for GPU mode - const [showNotification, setShowNotification] = useAtom( - isShowNotificationAtom - ) const [settings, setSettings] = useState() useEffect(() => { @@ -29,15 +23,6 @@ export const useSettings = () => { const validateSettings = async () => { readSettings().then((settings) => { - if ( - settings && - settings.notify && - ((settings.nvidia_driver?.exist && !settings.cuda?.exist) || - !settings.nvidia_driver?.exist) - ) { - setShowNotification(false) - } - // Check if run_mode is 'gpu' or 'cpu' and update state accordingly setIsGPUModeEnabled(settings?.run_mode === 'gpu') }) @@ -84,11 +69,9 @@ export const useSettings = () => { } return { - showNotification, isGPUModeEnabled, readSettings, saveSettings, - setShowNotification, validateSettings, settings, } diff --git a/web/screens/Settings/Advanced/index.tsx b/web/screens/Settings/Advanced/index.tsx index 035119accd..b8312258bb 100644 --- a/web/screens/Settings/Advanced/index.tsx +++ b/web/screens/Settings/Advanced/index.tsx @@ -67,8 +67,7 @@ const Advanced = () => { const [gpuList, setGpuList] = useState([]) const [gpusInUse, setGpusInUse] = useState([]) - const { readSettings, saveSettings, validateSettings, setShowNotification } = - useSettings() + const { readSettings, saveSettings, validateSettings } = useSettings() const { stopModel } = useActiveModel() const selectedGpu = gpuList @@ -273,7 +272,6 @@ const Advanced = () => { if (e === true) { saveSettings({ runMode: 'gpu' }) setGpuEnabled(true) - setShowNotification(false) snackbar({ description: 'Successfully turned on GPU Acceleration',