diff --git a/backend-python/routes/config.py b/backend-python/routes/config.py index 2ad6977..f4bec31 100644 --- a/backend-python/routes/config.py +++ b/backend-python/routes/config.py @@ -35,7 +35,8 @@ def switch_model(body: SwitchModelBody, response: Response): tokens_path=f"{pathlib.Path(__file__).parent.parent.resolve()}/20B_tokenizer.json", ), ) - except Exception: + except Exception as e: + print(e) global_var.set(global_var.Model_Status, global_var.ModelStatus.Offline) raise HTTPException(status.HTTP_500_INTERNAL_SERVER_ERROR, "failed to load") diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 8ed7363..fc527e4 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -87,7 +87,7 @@ const App: FC = observer(() => { { const port = commonStore.getCurrentModelConfig().apiParameters.apiPort; return fetch(`http://127.0.0.1:${port}`); }; -export const exit = async () => { - commonStore.setModelStatus(ModelStatus.Offline); +export const exit = async (timeout?: number) => { + const controller = new AbortController(); + if (timeout) + setTimeout(() => controller.abort(), timeout); + const port = commonStore.getCurrentModelConfig().apiParameters.apiPort; - return fetch(`http://127.0.0.1:${port}/exit`, {method: 'POST'}); + return fetch(`http://127.0.0.1:${port}/exit`, {method: 'POST', signal: controller.signal}); }; export const switchModel = async (body: any) => { diff --git a/frontend/src/components/RunButton.tsx b/frontend/src/components/RunButton.tsx index 7b890e1..b601d07 100644 --- a/frontend/src/components/RunButton.tsx +++ b/frontend/src/components/RunButton.tsx @@ -8,6 +8,7 @@ import {toast} from 'react-toastify'; import manifest from '../../../manifest.json'; import {getStrategy} from '../utils'; import {useTranslation} from 'react-i18next'; +import {t} from 'i18next'; const mainButtonText = { [ModelStatus.Offline]: 'Run', @@ -22,6 +23,8 @@ const onClickMainButton = async () => { if (commonStore.modelStatus === ModelStatus.Offline) { commonStore.setModelStatus(ModelStatus.Starting); + await exit(1000).catch(() => { + }); StartServer(port); let timeoutCount = 6; @@ -33,7 +36,7 @@ const onClickMainButton = async () => { clearInterval(intervalId); commonStore.setModelStatus(ModelStatus.Loading); loading = true; - toast('Loading Model', {type: 'info'}); + toast(t('Loading Model'), {type: 'info'}); updateConfig({ max_tokens: modelConfig.apiParameters.maxResponseToken, temperature: modelConfig.apiParameters.temperature, @@ -47,12 +50,12 @@ const onClickMainButton = async () => { }).then((r) => { if (r.ok) { commonStore.setModelStatus(ModelStatus.Working); - toast('Startup Completed', {type: 'success'}); + toast(t('Startup Completed'), {type: 'success'}); } else if (r.status === 304) { - toast('Loading Model', {type: 'info'}); + toast(t('Loading Model'), {type: 'info'}); } else { commonStore.setModelStatus(ModelStatus.Offline); - toast('Failed to switch model', {type: 'error'}); + toast(t('Failed to switch model'), {type: 'error'}); } }); } @@ -66,6 +69,7 @@ const onClickMainButton = async () => { timeoutCount--; }, 1000); } else { + commonStore.setModelStatus(ModelStatus.Offline); exit(); } }; diff --git a/frontend/src/pages/Configs.tsx b/frontend/src/pages/Configs.tsx index 6d00f4f..8c2afdc 100644 --- a/frontend/src/pages/Configs.tsx +++ b/frontend/src/pages/Configs.tsx @@ -64,7 +64,7 @@ export const Configs: FC = observer(() => { presence_penalty: selectedConfig.apiParameters.presencePenalty, frequency_penalty: selectedConfig.apiParameters.frequencyPenalty }); - toast('Config Saved', {autoClose: 300, type: 'success'}); + toast(t('Config Saved'), {autoClose: 300, type: 'success'}); }; return ( @@ -182,12 +182,12 @@ export const Configs: FC = observer(() => { const modelPath = `${manifest.localModelDir}/${selectedConfig.modelParameters.modelName}`; const strategy = getStrategy(selectedConfig); const newModelPath = modelPath + '-' + strategy.replace(/[> *+]/g, '-'); - toast('Start Converting', {autoClose: 1000, type: 'info'}); + toast(t('Start Converting'), {autoClose: 1000, type: 'info'}); ConvertModel(modelPath, strategy, newModelPath).then(() => { - toast(`Convert Success - ${newModelPath}`, {type: 'success'}); + toast(`${t('Convert Success')} - ${newModelPath}`, {type: 'success'}); refreshLocalModels({models: commonStore.modelSourceList}); }).catch(e => { - toast(`Convert Failed - ${e}`, {type: 'error'}); + toast(`${t('Convert Failed')} - ${e}`, {type: 'error'}); }); }}/> [] = [ } {item.downloadUrl && !item.isLocal && } onClick={() => { - toast(`Downloading ${item.name}`); + toast(`${t('Downloading')} ${item.name}`); DownloadFile(`./${manifest.localModelDir}/${item.name}`, item.downloadUrl!); }}/>} {item.url && } onClick={() => {