From 47e0535a1cedc2c406d72f6ce5496ddc2ead0b83 Mon Sep 17 00:00:00 2001 From: lin onetwo Date: Sun, 14 Apr 2024 00:04:23 +0800 Subject: [PATCH] fix: prevent abort throw error --- src/services/languageModel/index.ts | 2 +- src/services/languageModel/llmWorker/llamaCpp.ts | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/services/languageModel/index.ts b/src/services/languageModel/index.ts index 324cbc95..a00e0929 100644 --- a/src/services/languageModel/index.ts +++ b/src/services/languageModel/index.ts @@ -222,7 +222,7 @@ export class LanguageModel implements ILanguageModelService { }; void runLanguageModelObserverIIFE().catch(error => { const message = `${(error as Error).message} ${(error as Error).stack ?? 'no stack'}`; - logger.error(message, { id: conversationID, function: 'LanguageModel.runLanguageModel$.error' }); + logger.error(message, { id: conversationID, function: 'runLanguageModelObserverIIFE.error' }); void this.nativeService.showElectronMessageBox({ title: i18n.t('LanguageModel.RunModelError'), message, diff --git a/src/services/languageModel/llmWorker/llamaCpp.ts b/src/services/languageModel/llmWorker/llamaCpp.ts index a43a71a0..540375ac 100644 --- a/src/services/languageModel/llmWorker/llamaCpp.ts +++ b/src/services/languageModel/llmWorker/llamaCpp.ts @@ -21,6 +21,12 @@ export function loadLLamaAndModel( async function loadLLamaAndModelIIFE() { subscriber.next({ message: `library loaded, new LLM now with LLAMA_PREBUILT_BINS_DIRECTORY ${LLAMA_PREBUILT_BINS_DIRECTORY}`, ...loggerCommonMeta }); try { + // add an initial progress, so user immediately know load is started. + subscriber.next({ + type: 'progress', + percentage: 0.0001, + id: conversationID, + }); llamaInstance = await getLlama({ skipDownload: true, vramPadding: 0, @@ -160,8 +166,12 @@ export function runLLama( subscriber.complete(); subscriber.next({ message: 'createCompletion completed', ...loggerCommonMeta }); } catch (error) { - runnerAbortControllers.delete(conversationID); - subscriber.error(error); + if ((error as Error).message.includes('aborted')) { + console.info('abortLLama', conversationID); + } else { + runnerAbortControllers.delete(conversationID); + subscriber.error(error); + } } })(); });