import React, { FC, useEffect, useRef } from 'react'; import { Page } from '../components/Page'; import { Accordion, AccordionHeader, AccordionItem, AccordionPanel, Dropdown, Input, Option, Switch } from '@fluentui/react-components'; import { Labeled } from '../components/Labeled'; import commonStore from '../stores/commonStore'; import { observer } from 'mobx-react-lite'; import { useTranslation } from 'react-i18next'; import { checkUpdate, toastWithButton } from '../utils'; import { RestartApp } from '../../wailsjs/go/backend_golang/App'; export const Languages = { dev: 'English', // i18n default zh: '简体中文' }; export type Language = keyof typeof Languages; export type SettingsType = { language: Language darkMode: boolean autoUpdatesCheck: boolean giteeUpdatesSource: boolean cnMirror: boolean host: string dpiScaling: number customModelsPath: string customPythonPath: string apiUrl: string apiKey: string apiChatModelName: string apiCompletionModelName: string } export const Settings: FC = observer(() => { const { t, i18n } = useTranslation(); const advancedHeaderRef = useRef(null); useEffect(() => { if (advancedHeaderRef.current) (advancedHeaderRef.current.firstElementChild as HTMLElement).style.padding = '0'; }, []); return ( { if (data.optionValue) { const lang = data.optionValue as Language; commonStore.setSettings({ language: lang }); } }}> { Object.entries(Languages).map(([langKey, desc]) => ) } } /> { commonStore.platform === 'windows' && { if (data.optionValue) { commonStore.setSettings({ dpiScaling: Number(data.optionValue) }); toastWithButton(t('Restart the app to apply DPI Scaling.'), t('Restart'), () => { RestartApp(); }, { autoClose: 5000 }); } }}> { Array.from({ length: 7 }, (_, i) => (i + 2) * 25).map((v, i) => ) } } /> } { commonStore.setSettings({ darkMode: data.checked }); }} /> } /> { commonStore.setSettings({ autoUpdatesCheck: data.checked }); if (data.checked) checkUpdate(true); }} /> } /> { commonStore.settings.language === 'zh' && { commonStore.setSettings({ giteeUpdatesSource: data.checked }); }} /> } /> } { commonStore.settings.language === 'zh' && commonStore.platform != 'linux' && { commonStore.setSettings({ cnMirror: data.checked }); }} /> } /> } { commonStore.setSettings({ host: data.checked ? '0.0.0.0' : '127.0.0.1' }); }} /> } /> { if (data.value === 'advanced') commonStore.setAdvancedCollapsed(!commonStore.advancedCollapsed); }}> {t('Advanced')}
{commonStore.platform !== 'darwin' && { commonStore.setSettings({ customModelsPath: data.value }); }} /> } /> } { commonStore.setDepComplete(false); commonStore.setSettings({ customPythonPath: data.value }); }} /> } /> { commonStore.setSettings({ apiUrl: data.value }); }} /> { commonStore.setSettings({ apiUrl: data.optionValue }); if (data.optionText === 'OpenAI') { if (commonStore.settings.apiChatModelName === 'rwkv') commonStore.setSettings({ apiChatModelName: 'gpt-3.5-turbo' }); if (commonStore.settings.apiCompletionModelName === 'rwkv') commonStore.setSettings({ apiCompletionModelName: 'text-davinci-003' }); } }}>
} /> { commonStore.setSettings({ apiKey: data.value }); }} /> } /> { commonStore.setSettings({ apiChatModelName: data.value }); }} /> { if (data.optionValue) { commonStore.setSettings({ apiChatModelName: data.optionValue }); } }}> { ['rwkv', 'gpt-4', 'gpt-4-0613', 'gpt-4-32k', 'gpt-4-32k-0613', 'gpt-3.5-turbo', 'gpt-3.5-turbo-0613', 'gpt-3.5-turbo-16k', 'gpt-3.5-turbo-16k-0613'] .map((v, i) => ) } } /> { commonStore.setSettings({ apiCompletionModelName: data.value }); }} /> { if (data.optionValue) { commonStore.setSettings({ apiCompletionModelName: data.optionValue }); } }}> { ['rwkv', 'text-davinci-003', 'text-davinci-002', 'text-curie-001', 'text-babbage-001', 'text-ada-001'] .map((v, i) => ) } } />
} /> ); });