1
1
mirror of https://github.com/leon-ai/leon.git synced 2024-08-17 06:00:33 +03:00

feat(scripts): fallback to mirror in case of error to download LLM

This commit is contained in:
louistiti 2024-04-22 00:00:46 +08:00
parent d8660251af
commit 4ca32b5070
No known key found for this signature in database
GPG Key ID: 92CD6A2E497E1669
4 changed files with 29 additions and 21 deletions

View File

@ -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",

View File

@ -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)
}
}
}

View File

@ -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)
}

View File

@ -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