From 4ca32b50703814277a0f3ac45aaba4f20104d193 Mon Sep 17 00:00:00 2001 From: louistiti Date: Mon, 22 Apr 2024 00:00:46 +0800 Subject: [PATCH] feat(scripts): fallback to mirror in case of error to download LLM --- core/skills-endpoints.json | 22 +++++++++---------- scripts/setup/setup-llm.js | 16 ++++++++++---- server/src/core/nlp/nlu/slot-filling.ts | 8 +++++-- .../translator-poc/src/actions/translate.ts | 4 ---- 4 files changed, 29 insertions(+), 21 deletions(-) diff --git a/core/skills-endpoints.json b/core/skills-endpoints.json index d8258002..0ecc3d79 100644 --- a/core/skills-endpoints.json +++ b/core/skills-endpoints.json @@ -52,6 +52,17 @@ "route": "/api/action/games/rochambeau/rematch", "params": [] }, + { + "method": "POST", + "route": "/api/action/news/github_trends/run", + "params": ["number", "daterange"], + "entitiesType": "builtIn" + }, + { + "method": "GET", + "route": "/api/action/news/product_hunt_trends/run", + "params": [] + }, { "method": "GET", "route": "/api/action/leon/age/run", @@ -127,17 +138,6 @@ "route": "/api/action/leon/welcome/run", "params": [] }, - { - "method": "POST", - "route": "/api/action/news/github_trends/run", - "params": ["number", "daterange"], - "entitiesType": "builtIn" - }, - { - "method": "GET", - "route": "/api/action/news/product_hunt_trends/run", - "params": [] - }, { "method": "POST", "route": "/api/action/productivity/todo_list/create_list", diff --git a/scripts/setup/setup-llm.js b/scripts/setup/setup-llm.js index 4226eecc..c6ceb909 100644 --- a/scripts/setup/setup-llm.js +++ b/scripts/setup/setup-llm.js @@ -47,7 +47,7 @@ async function canAccessHuggingFace() { } } -async function downloadLLM() { +async function downloadLLM(retryWithMirror = false) { try { LogHelper.info('Downloading LLM...') @@ -61,9 +61,10 @@ async function downloadLLM() { } if (!manifest || manifest.version !== LLM_VERSION) { - const downloadURL = (await canAccessHuggingFace()) - ? LLM_HF_DOWNLOAD_URL - : LLM_MIRROR_DOWNLOAD_URL + const downloadURL = + (await canAccessHuggingFace()) && !retryWithMirror + ? LLM_HF_DOWNLOAD_URL + : LLM_MIRROR_DOWNLOAD_URL // Just in case the LLM file already exists, delete it first if (fs.existsSync(LLM_PATH)) { @@ -89,6 +90,13 @@ async function downloadLLM() { } } catch (e) { LogHelper.error(`Failed to download LLM: ${e}`) + + if (e.code === 'EAI_AGAIN') { + LogHelper.warning( + 'Failed to download from Hugging Face, retrying from mirror...' + ) + await downloadLLM(true) + } } } diff --git a/server/src/core/nlp/nlu/slot-filling.ts b/server/src/core/nlp/nlu/slot-filling.ts index 8eb57db0..3ed72822 100644 --- a/server/src/core/nlp/nlu/slot-filling.ts +++ b/server/src/core/nlp/nlu/slot-filling.ts @@ -111,7 +111,11 @@ export class SlotFilling { if (!NLU.conversation.areSlotsAllFilled()) { BRAIN.talk(`${BRAIN.wernicke('random_context_out_of_topic')}.`) } else { - console.log('slot filling active context', NLU.conversation.activeContext) + console.log( + 'slot filling active context', + utterance, + NLU.conversation.activeContext + ) NLU.nluResult = { ...DEFAULT_NLU_RESULT, // Reset entities, slots, etc. @@ -129,7 +133,7 @@ export class SlotFilling { } } - // NLU.conversation.cleanActiveContext() + NLU.conversation.cleanActiveContext() return BRAIN.execute(NLU.nluResult) } diff --git a/skills/utilities/translator-poc/src/actions/translate.ts b/skills/utilities/translator-poc/src/actions/translate.ts index 0fd6022c..93da237b 100644 --- a/skills/utilities/translator-poc/src/actions/translate.ts +++ b/skills/utilities/translator-poc/src/actions/translate.ts @@ -34,10 +34,6 @@ export const run: ActionFunction = async function (params) { await leon.answer({ key: 'translate', - core: { - isInActionLoop: true, - restart: true - }, data: { output: `just a test ${targetLanguage} ${textToTranslate}` // output: response.data.output.translation