improve details

This commit is contained in:
josc146 2023-05-21 12:54:37 +08:00
parent d4d71898ed
commit c02ce51d86
3 changed files with 306 additions and 286 deletions

View File

@ -95,5 +95,6 @@
"Python dependencies are incomplete, would you like to install them?": "Python依赖缺失, 是否安装?", "Python dependencies are incomplete, would you like to install them?": "Python依赖缺失, 是否安装?",
"Install": "安装", "Install": "安装",
"This is the latest version": "已是最新版", "This is the latest version": "已是最新版",
"Use Tsinghua Pip Mirrors": "使用清华大学Pip镜像源" "Use Tsinghua Pip Mirrors": "使用清华大学Pip镜像源",
"Model Config Exception": "模型配置异常"
} }

View File

@ -11,6 +11,7 @@ import {useTranslation} from 'react-i18next';
import { ToolTipButton } from './ToolTipButton'; import { ToolTipButton } from './ToolTipButton';
import { Play16Regular, Stop16Regular } from '@fluentui/react-icons'; import { Play16Regular, Stop16Regular } from '@fluentui/react-icons';
import { useNavigate } from 'react-router'; import { useNavigate } from 'react-router';
import { WindowShow } from '../../wailsjs/runtime/runtime';
const mainButtonText = { const mainButtonText = {
[ModelStatus.Offline]: 'Run', [ModelStatus.Offline]: 'Run',
@ -35,14 +36,26 @@ export const RunButton: FC<{ onClickRun?: MouseEventHandler, iconMode?: boolean
const navigate = useNavigate(); const navigate = useNavigate();
const onClickMainButton = async () => { const onClickMainButton = async () => {
if (commonStore.modelStatus === ModelStatus.Offline) {
commonStore.setModelStatus(ModelStatus.Starting);
const modelConfig = commonStore.getCurrentModelConfig(); const modelConfig = commonStore.getCurrentModelConfig();
const modelName = modelConfig.modelParameters.modelName; let modelName = ''
const modelPath = `./${manifest.localModelDir}/${modelName}`; let modelPath = ''
if (modelConfig && modelConfig.modelParameters) {
modelName = modelConfig.modelParameters.modelName;
modelPath = `./${manifest.localModelDir}/${modelName}`;
} else {
toast(t('Model Config Exception'), { type: 'error' });
commonStore.setModelStatus(ModelStatus.Offline);
return;
}
if (!commonStore.depComplete) { if (!commonStore.depComplete) {
let depErrorMsg = ''; let depErrorMsg = '';
await DepCheck().catch((e) => { await DepCheck().catch((e) => {
depErrorMsg = e.message || e; depErrorMsg = e.message || e;
WindowShow();
if (depErrorMsg === 'python zip not found') { if (depErrorMsg === 'python zip not found') {
toastWithButton(t('Python target not found, would you like to download it?'), t('Download'), () => { toastWithButton(t('Python target not found, would you like to download it?'), t('Download'), () => {
toastWithButton(`${t('Downloading')} Python`, t('Check'), () => { toastWithButton(`${t('Downloading')} Python`, t('Check'), () => {
@ -53,12 +66,14 @@ export const RunButton: FC<{ onClickRun?: MouseEventHandler, iconMode?: boolean
} else if (depErrorMsg.includes('DepCheck Error')) { } else if (depErrorMsg.includes('DepCheck Error')) {
toastWithButton(t('Python dependencies are incomplete, would you like to install them?'), t('Install'), () => { toastWithButton(t('Python dependencies are incomplete, would you like to install them?'), t('Install'), () => {
InstallPyDep(commonStore.settings.cnMirror); InstallPyDep(commonStore.settings.cnMirror);
setTimeout(WindowShow, 1000)
}); });
} else { } else {
toast(depErrorMsg, { type: 'error' }); toast(depErrorMsg, { type: 'error' });
} }
}); });
if (depErrorMsg) { if (depErrorMsg) {
commonStore.setModelStatus(ModelStatus.Offline);
return; return;
} }
commonStore.setDepComplete(true); commonStore.setDepComplete(true);
@ -79,16 +94,16 @@ export const RunButton: FC<{ onClickRun?: MouseEventHandler, iconMode?: boolean
} }
}); });
commonStore.setModelStatus(ModelStatus.Offline);
return; return;
} }
const port = modelConfig.apiParameters.apiPort; const port = modelConfig.apiParameters.apiPort;
if (commonStore.modelStatus === ModelStatus.Offline) {
commonStore.setModelStatus(ModelStatus.Starting);
await exit(1000).catch(() => { await exit(1000).catch(() => {
}); });
StartServer(port); StartServer(port);
setTimeout(WindowShow, 1000)
let timeoutCount = 6; let timeoutCount = 6;
let loading = false; let loading = false;
@ -113,7 +128,9 @@ export const RunButton: FC<{ onClickRun?: MouseEventHandler, iconMode?: boolean
}).then((r) => { }).then((r) => {
if (r.ok) { if (r.ok) {
commonStore.setModelStatus(ModelStatus.Working); commonStore.setModelStatus(ModelStatus.Working);
toast(t('Startup Completed'), {type: 'success'}); toastWithButton(t('Startup Completed'), t('Chat'), () => {
navigate({ pathname: '/chat' });
}, { type: 'success', autoClose: 3000 });
} else if (r.status === 304) { } else if (r.status === 304) {
toast(t('Loading Model'), { type: 'info' }); toast(t('Loading Model'), { type: 'info' });
} else { } else {

View File

@ -17,6 +17,7 @@ import {ConvertModel, FileExists} from '../../wailsjs/go/backend_golang/App';
import manifest from '../../../manifest.json'; import manifest from '../../../manifest.json';
import { getStrategy, refreshLocalModels } from '../utils'; import { getStrategy, refreshLocalModels } from '../utils';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { WindowShow } from '../../wailsjs/runtime/runtime';
export type ApiParameters = { export type ApiParameters = {
apiPort: number apiPort: number
@ -258,6 +259,7 @@ export const Configs: FC = observer(() => {
}).catch(e => { }).catch(e => {
toast(`${t('Convert Failed')} - ${e.message || e}`, { type: 'error' }); toast(`${t('Convert Failed')} - ${e.message || e}`, { type: 'error' });
}); });
setTimeout(WindowShow, 1000)
} else { } else {
toast(`${t('Model Not Found')} - ${modelPath}`, { type: 'error' }); toast(`${t('Model Not Found')} - ${modelPath}`, { type: 'error' });
} }