mirror of
https://github.com/leon-ai/leon.git
synced 2024-09-11 18:27:21 +03:00
feat(scripts): fallback to mirror in case of error to download LLM
This commit is contained in:
parent
d8660251af
commit
4ca32b5070
@ -52,6 +52,17 @@
|
|||||||
"route": "/api/action/games/rochambeau/rematch",
|
"route": "/api/action/games/rochambeau/rematch",
|
||||||
"params": []
|
"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",
|
"method": "GET",
|
||||||
"route": "/api/action/leon/age/run",
|
"route": "/api/action/leon/age/run",
|
||||||
@ -127,17 +138,6 @@
|
|||||||
"route": "/api/action/leon/welcome/run",
|
"route": "/api/action/leon/welcome/run",
|
||||||
"params": []
|
"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",
|
"method": "POST",
|
||||||
"route": "/api/action/productivity/todo_list/create_list",
|
"route": "/api/action/productivity/todo_list/create_list",
|
||||||
|
@ -47,7 +47,7 @@ async function canAccessHuggingFace() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function downloadLLM() {
|
async function downloadLLM(retryWithMirror = false) {
|
||||||
try {
|
try {
|
||||||
LogHelper.info('Downloading LLM...')
|
LogHelper.info('Downloading LLM...')
|
||||||
|
|
||||||
@ -61,9 +61,10 @@ async function downloadLLM() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!manifest || manifest.version !== LLM_VERSION) {
|
if (!manifest || manifest.version !== LLM_VERSION) {
|
||||||
const downloadURL = (await canAccessHuggingFace())
|
const downloadURL =
|
||||||
? LLM_HF_DOWNLOAD_URL
|
(await canAccessHuggingFace()) && !retryWithMirror
|
||||||
: LLM_MIRROR_DOWNLOAD_URL
|
? LLM_HF_DOWNLOAD_URL
|
||||||
|
: LLM_MIRROR_DOWNLOAD_URL
|
||||||
|
|
||||||
// Just in case the LLM file already exists, delete it first
|
// Just in case the LLM file already exists, delete it first
|
||||||
if (fs.existsSync(LLM_PATH)) {
|
if (fs.existsSync(LLM_PATH)) {
|
||||||
@ -89,6 +90,13 @@ async function downloadLLM() {
|
|||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
LogHelper.error(`Failed to download LLM: ${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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,7 +111,11 @@ export class SlotFilling {
|
|||||||
if (!NLU.conversation.areSlotsAllFilled()) {
|
if (!NLU.conversation.areSlotsAllFilled()) {
|
||||||
BRAIN.talk(`${BRAIN.wernicke('random_context_out_of_topic')}.`)
|
BRAIN.talk(`${BRAIN.wernicke('random_context_out_of_topic')}.`)
|
||||||
} else {
|
} else {
|
||||||
console.log('slot filling active context', NLU.conversation.activeContext)
|
console.log(
|
||||||
|
'slot filling active context',
|
||||||
|
utterance,
|
||||||
|
NLU.conversation.activeContext
|
||||||
|
)
|
||||||
|
|
||||||
NLU.nluResult = {
|
NLU.nluResult = {
|
||||||
...DEFAULT_NLU_RESULT, // Reset entities, slots, etc.
|
...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)
|
return BRAIN.execute(NLU.nluResult)
|
||||||
}
|
}
|
||||||
|
@ -34,10 +34,6 @@ export const run: ActionFunction = async function (params) {
|
|||||||
|
|
||||||
await leon.answer({
|
await leon.answer({
|
||||||
key: 'translate',
|
key: 'translate',
|
||||||
core: {
|
|
||||||
isInActionLoop: true,
|
|
||||||
restart: true
|
|
||||||
},
|
|
||||||
data: {
|
data: {
|
||||||
output: `just a test ${targetLanguage} ${textToTranslate}`
|
output: `just a test ${targetLanguage} ${textToTranslate}`
|
||||||
// output: response.data.output.translation
|
// output: response.data.output.translation
|
||||||
|
Loading…
Reference in New Issue
Block a user