From 7ce464ecda90f71b72ee546060789ca8b79e8184 Mon Sep 17 00:00:00 2001 From: josc146 Date: Sun, 26 Nov 2023 22:54:59 +0800 Subject: [PATCH] improve details --- backend-golang/download.go | 6 +++--- frontend/src/components/RunButton.tsx | 14 ++++++++++++-- frontend/src/pages/Chat.tsx | 2 +- frontend/src/utils/convert-to-st.ts | 3 ++- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/backend-golang/download.go b/backend-golang/download.go index cf52816..88a8b75 100644 --- a/backend-golang/download.go +++ b/backend-golang/download.go @@ -33,9 +33,9 @@ type DownloadStatus struct { var downloadList []*DownloadStatus -func existsInDownloadList(url string) bool { +func existsInDownloadList(path string, url string) bool { for _, ds := range downloadList { - if ds.Url == url { + if ds.Path == path || ds.Url == url { return true } } @@ -88,7 +88,7 @@ func (a *App) ContinueDownload(url string) { } func (a *App) AddToDownloadList(path string, url string) { - if !existsInDownloadList(url) { + if !existsInDownloadList(a.exDir+path, url) { downloadList = append(downloadList, &DownloadStatus{ resp: nil, Name: filepath.Base(path), diff --git a/frontend/src/components/RunButton.tsx b/frontend/src/components/RunButton.tsx index 4303a38..f8dbd9d 100644 --- a/frontend/src/components/RunButton.tsx +++ b/frontend/src/components/RunButton.tsx @@ -84,6 +84,10 @@ export const RunButton: FC<{ onClickRun?: MouseEventHandler, iconMode?: boolean showDownloadPrompt(t('Model file not found'), modelName); commonStore.setStatus({ status: ModelStatus.Offline }); return; + } else if (!currentModelSource?.isComplete) { + showDownloadPrompt(t('Model file download is not complete'), modelName); + commonStore.setStatus({ status: ModelStatus.Offline }); + return; } else { toastWithButton(t('Please convert model to safe tensors format first'), t('Convert'), () => { convertToSt(navigate, modelConfig); @@ -112,7 +116,9 @@ export const RunButton: FC<{ onClickRun?: MouseEventHandler, iconMode?: boolean showDownloadPrompt(t('Model file not found'), modelName); commonStore.setStatus({ status: ModelStatus.Offline }); return; - } else if (!currentModelSource?.isComplete) { + } else // If the user selects the .pth model with WebGPU mode, modelPath will be set to the .st model. + // However, if the .pth model is deleted, modelPath will exist and isComplete will be false. + if (!currentModelSource?.isComplete && modelPath.endsWith('.pth')) { showDownloadPrompt(t('Model file download is not complete'), modelName); commonStore.setStatus({ status: ModelStatus.Offline }); return; @@ -145,6 +151,8 @@ export const RunButton: FC<{ onClickRun?: MouseEventHandler, iconMode?: boolean toast(t('Error') + ' - ' + errMsg, { type: 'error' }); }); setTimeout(WindowShow, 1000); + setTimeout(WindowShow, 2000); + setTimeout(WindowShow, 3000); let timeoutCount = 6; let loading = false; @@ -161,7 +169,7 @@ export const RunButton: FC<{ onClickRun?: MouseEventHandler, iconMode?: boolean }); } commonStore.setStatus({ status: ModelStatus.Loading }); - toast(t('Loading Model'), { type: 'info' }); + const loadingId = toast(t('Loading Model'), { type: 'info' }); if (!webgpu) { updateConfig({ max_tokens: modelConfig.apiParameters.maxResponseToken, @@ -247,6 +255,8 @@ export const RunButton: FC<{ onClickRun?: MouseEventHandler, iconMode?: boolean }).catch((e) => { commonStore.setStatus({ status: ModelStatus.Offline }); toast(t('Failed to switch model') + ' - ' + (e.message || e), { type: 'error' }); + }).finally(() => { + toast.dismiss(loadingId); }); } }).catch(() => { diff --git a/frontend/src/pages/Chat.tsx b/frontend/src/pages/Chat.tsx index f3bced0..6fed0ce 100644 --- a/frontend/src/pages/Chat.tsx +++ b/frontend/src/pages/Chat.tsx @@ -567,7 +567,7 @@ const ChatPanel: FC = observer(() => { const filterPattern = '*.txt;*.pdf'; const setUploading = () => commonStore.setAttachmentUploading(true); // actually, status of web platform is always Offline - if (commonStore.platform === 'web' || commonStore.status.status === ModelStatus.Offline) { + if (commonStore.platform === 'web' || commonStore.status.status === ModelStatus.Offline || currentConfig.modelParameters.device === 'WebGPU') { webOpenOpenFileDialog({ filterPattern, fnStartLoading: setUploading }).then(webReturn => { if (webReturn.content) commonStore.setCurrentTempAttachment( diff --git a/frontend/src/utils/convert-to-st.ts b/frontend/src/utils/convert-to-st.ts index 6badb57..5b16ba5 100644 --- a/frontend/src/utils/convert-to-st.ts +++ b/frontend/src/utils/convert-to-st.ts @@ -23,7 +23,8 @@ export const convertToSt = async (navigate: NavigateFunction, selectedConfig: Mo const newModelPath = modelPath.replace(/\.pth$/, '.st'); ConvertSafetensors(commonStore.settings.customPythonPath, modelPath, newModelPath).then(async () => { if (!await FileExists(newModelPath)) { - toast(t('Convert Failed') + ' - ' + await GetPyError(), { type: 'error' }); + if (commonStore.platform === 'windows') + toast(t('Convert Failed') + ' - ' + await GetPyError(), { type: 'error' }); } else { toast(`${t('Convert Success')} - ${newModelPath}`, { type: 'success' }); }