From 447f4572b1771c8f38ae331fb6e4fa73fac7c7a2 Mon Sep 17 00:00:00 2001 From: josc146 Date: Fri, 23 Jun 2023 13:55:45 +0800 Subject: [PATCH] improve error messages --- frontend/src/_locales/zh-hans/main.json | 7 ++++++- frontend/src/components/RunButton.tsx | 14 ++++++++++++-- frontend/src/pages/Chat.tsx | 2 +- frontend/src/utils/index.tsx | 4 ++-- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/frontend/src/_locales/zh-hans/main.json b/frontend/src/_locales/zh-hans/main.json index edd905c..1a06e95 100644 --- a/frontend/src/_locales/zh-hans/main.json +++ b/frontend/src/_locales/zh-hans/main.json @@ -157,5 +157,10 @@ "Localhost": "本地", "Retry": "重试", "Delete": "删除", - "Edit": "编辑" + "Edit": "编辑", + "Memory is not enough, try to increase the virtual memory or use a smaller model.": "内存不足,尝试增加虚拟内存,或使用一个更小规模的模型", + "Bad pytorch version, please reinstall pytorch with cuda.": "错误的Pytorch版本,请重新安装CUDA版本的Pytorch", + "The model file is corrupted, please download again.": "模型文件损坏,请重新下载", + "Found no NVIDIA driver, please install the latest driver.": "没有找到NVIDIA驱动,请安装最新驱动", + "VRAM is not enough, please reduce stored layers or use a lower precision in Configs page.": "显存不足,请在配置页面减少载入显存层数,或使用更低的精度" } \ No newline at end of file diff --git a/frontend/src/components/RunButton.tsx b/frontend/src/components/RunButton.tsx index 76a9733..cc9396f 100644 --- a/frontend/src/components/RunButton.tsx +++ b/frontend/src/components/RunButton.tsx @@ -207,11 +207,21 @@ export const RunButton: FC<{ onClickRun?: MouseEventHandler, iconMode?: boolean toast(t('Loading Model'), { type: 'info' }); } else { commonStore.setStatus({ status: ModelStatus.Offline }); - toast(t('Failed to switch model') + ' - ' + await r.text(), { type: 'error' }); + const error = await r.text(); + const errorsMap = { + 'not enough memory': 'Memory is not enough, try to increase the virtual memory or use a smaller model.', + 'not compiled with CUDA': 'Bad pytorch version, please reinstall pytorch with cuda.', + 'invalid header or archive is corrupted': 'The model file is corrupted, please download again.', + 'no NVIDIA driver': 'Found no NVIDIA driver, please install the latest driver.', + 'CUDA out of memory': 'VRAM is not enough, please reduce stored layers or use a lower precision in Configs page.' + }; + const matchedError = Object.entries(errorsMap).find(([key, _]) => error.includes(key)); + const message = matchedError ? t(matchedError[1]) : error; + toast(t('Failed to switch model') + ' - ' + message, { autoClose: 5000, type: 'error' }); } }).catch((e) => { commonStore.setStatus({ status: ModelStatus.Offline }); - toast(t('Failed to switch model') + ' - ' + e.message || e, { type: 'error' }); + toast(t('Failed to switch model') + ' - ' + (e.message || e), { type: 'error' }); }); } }).catch(() => { diff --git a/frontend/src/pages/Chat.tsx b/frontend/src/pages/Chat.tsx index 2871513..ffd34d2 100644 --- a/frontend/src/pages/Chat.tsx +++ b/frontend/src/pages/Chat.tsx @@ -409,7 +409,7 @@ const ChatPanel: FC = observer(() => { OpenFileFolder(path, false); }); }).catch(e => { - toast(t('Error') + ' - ' + e.message || e, { type: 'error', autoClose: 2500 }); + toast(t('Error') + ' - ' + (e.message || e), { type: 'error', autoClose: 2500 }); }); }} /> diff --git a/frontend/src/utils/index.tsx b/frontend/src/utils/index.tsx index 426bc14..1b9e2ad 100644 --- a/frontend/src/utils/index.tsx +++ b/frontend/src/utils/index.tsx @@ -270,7 +270,7 @@ export async function checkUpdate(notifyEvenLatest: boolean = false) { } ); }).catch((e) => { - toast(t('Update Error') + ' - ' + e.message || e, { + toast(t('Update Error') + ' - ' + (e.message || e), { type: 'error', position: 'bottom-left', autoClose: false @@ -302,7 +302,7 @@ export async function checkUpdate(notifyEvenLatest: boolean = false) { } } ).catch((e) => { - toast(t('Updates Check Error') + ' - ' + e.message || e, { type: 'error', position: 'bottom-left' }); + toast(t('Updates Check Error') + ' - ' + (e.message || e), { type: 'error', position: 'bottom-left' }); }); }