'use client' import { useContext, useEffect, useState, useCallback, ChangeEvent, } from 'react' import { openExternalUrl, fs } from '@janhq/core' import { Switch, Button, Input, Select, Checkbox, SelectContent, SelectGroup, SelectPortal, SelectLabel, SelectTrigger, SelectValue, Tooltip, TooltipArrow, TooltipContent, TooltipTrigger, ScrollArea, } from '@janhq/uikit' import { AlertTriangleIcon, AlertCircleIcon } from 'lucide-react' import ShortcutModal from '@/containers/ShortcutModal' import { snackbar, toaster } from '@/containers/Toast' import { FeatureToggleContext } from '@/context/FeatureToggle' import { useActiveModel } from '@/hooks/useActiveModel' import { useSettings } from '@/hooks/useSettings' import DataFolder from './DataFolder' import FactoryReset from './FactoryReset' type GPU = { id: string vram: number | null name: string } const Advanced = () => { const { experimentalFeature, setExperimentalFeature, ignoreSSL, setIgnoreSSL, proxy, setProxy, proxyEnabled, setProxyEnabled, vulkanEnabled, setVulkanEnabled, } = useContext(FeatureToggleContext) const [partialProxy, setPartialProxy] = useState(proxy) const [gpuEnabled, setGpuEnabled] = useState(false) const [gpuList, setGpuList] = useState([]) const [gpusInUse, setGpusInUse] = useState([]) const { readSettings, saveSettings, validateSettings, setShowNotification } = useSettings() const { stopModel } = useActiveModel() const selectedGpu = gpuList .filter((x) => gpusInUse.includes(x.id)) .map((y) => { return y['name'] }) const onProxyChange = useCallback( (event: ChangeEvent) => { const value = event.target.value || '' setPartialProxy(value) if (value.trim().startsWith('http')) { setProxy(value.trim()) } else { setProxy('') } }, [setPartialProxy, setProxy] ) useEffect(() => { const setUseGpuIfPossible = async () => { const settings = await readSettings() setGpuEnabled(settings.run_mode === 'gpu' && settings.gpus?.length > 0) setGpusInUse(settings.gpus_in_use || []) setVulkanEnabled(settings.vulkan || false) if (settings.gpus) { setGpuList(settings.gpus) } } setUseGpuIfPossible() }, [readSettings, setGpuList, setGpuEnabled, setGpusInUse, setVulkanEnabled]) const clearLogs = async () => { if (await fs.existsSync(`file://logs`)) { await fs.rmdirSync(`file://logs`, { recursive: true }) } toaster({ title: 'Logs cleared', description: 'All logs have been cleared.', type: 'success', }) } const handleGPUChange = (gpuId: string) => { let updatedGpusInUse = [...gpusInUse] if (updatedGpusInUse.includes(gpuId)) { updatedGpusInUse = updatedGpusInUse.filter((id) => id !== gpuId) if (gpuEnabled && updatedGpusInUse.length === 0) { // Vulkan support only allow 1 active device at a time if (vulkanEnabled) { updatedGpusInUse = [] } updatedGpusInUse.push(gpuId) } } else { // Vulkan support only allow 1 active device at a time if (vulkanEnabled) { updatedGpusInUse = [] } updatedGpusInUse.push(gpuId) } setGpusInUse(updatedGpusInUse) saveSettings({ gpusInUse: updatedGpusInUse }) } const gpuSelectionPlaceHolder = gpuList.length > 0 ? 'Select GPU' : "You don't have any compatible GPU" return (
{/* Keyboard shortcut */}
Keyboard Shortcuts

Shortcuts that you might find useful in Jan app.

{/* Experimental */}
Experimental Mode

Enable experimental features that may be unstable tested.

{/* CPU / GPU switching */} {!isMac && (
GPU Acceleration

Enable to enhance model performance by utilizing your GPU devices for acceleration. Read{' '} {' '} openExternalUrl( 'https://jan.ai/guides/troubleshooting/gpu-not-used/' ) } > troubleshooting guide {' '} {' '} for further assistance.

{gpuList.length > 0 && !gpuEnabled && ( Disabling NVIDIA GPU Acceleration may result in reduced performance. It is recommended to keep this enabled for optimal user experience. )} { if (e === true) { saveSettings({ runMode: 'gpu' }) setGpuEnabled(true) setShowNotification(false) snackbar({ description: 'Successfully turned on GPU Accelertion', type: 'success', }) setTimeout(() => { validateSettings() }, 300) } else { saveSettings({ runMode: 'cpu' }) setGpuEnabled(false) snackbar({ description: 'Successfully turned off GPU Accelertion', type: 'success', }) } // Stop any running model to apply the changes if (e !== gpuEnabled) stopModel() }} /> {gpuList.length === 0 && ( Your current device does not have a compatible GPU for monitoring. To enable GPU monitoring, please ensure your device has a supported Nvidia or AMD GPU with updated drivers. )}
)} {/* Vulkan for AMD GPU/ APU and Intel Arc GPU */} {!isMac && experimentalFeature && (
Vulkan Support

Enable Vulkan with AMD GPU/APU and Intel Arc GPU for better model performance (reload needed).

{ toaster({ title: 'Reload', description: 'Vulkan settings updated. Reload now to apply the changes.', }) stopModel() saveSettings({ vulkan: e, gpusInUse: [] }) setVulkanEnabled(e) }} />
)} {/* Proxy */}
HTTPS Proxy
setProxyEnabled(!proxyEnabled)} />

Specify the HTTPS proxy or leave blank (proxy auto-configuration and SOCKS not supported).

:@:'} value={partialProxy} onChange={onProxyChange} className="w-2/3" />
{/* Ignore SSL certificates */}
Ignore SSL certificates

Allow self-signed or unverified certificates - may be required for certain proxies.

setIgnoreSSL(e)} />
{/* Clear log */}
Clear logs

Clear all logs from Jan app.

{/* Factory Reset */}
) } export default Advanced