1
1
mirror of https://github.com/leon-ai/leon.git synced 2025-01-02 13:43:51 +03:00

feat(server): add minimum RAM requirement on pre-check

This commit is contained in:
louistiti 2023-04-30 10:31:18 +08:00
parent 0a14567776
commit c3452d2170
No known key found for this signature in database
GPG Key ID: 92CD6A2E497E1669
3 changed files with 31 additions and 5 deletions

View File

@ -14,6 +14,7 @@ import getos from 'getos'
import { LogHelper } from '@/helpers/log-helper'
import { SystemHelper } from '@/helpers/system-helper'
import {
MINIMUM_REQUIRED_RAM,
LEON_VERSION,
PYTHON_BRIDGE_BIN_PATH,
TCP_SERVER_BIN_PATH,
@ -31,7 +32,6 @@ dotenv.config()
try {
const nodeMinRequiredVersion = '16'
const npmMinRequiredVersion = '8'
const minimumRequiredRAM = 4
const flitePath = 'bin/flite/flite'
const coquiLanguageModelPath = 'bin/coqui/huge-vocabulary.scorer'
const amazonPath = 'core/config/voice/amazon.json'
@ -144,10 +144,10 @@ dotenv.config()
}
const totalRAMInGB = SystemHelper.getTotalRAM()
if (Math.round(totalRAMInGB) < minimumRequiredRAM) {
if (Math.round(totalRAMInGB) < MINIMUM_REQUIRED_RAM) {
report.can_run.v = false
LogHelper.error(
`Total RAM: ${totalRAMInGB} GB. Leon needs at least ${minimumRequiredRAM} GB of RAM`
`Total RAM: ${totalRAMInGB} GB. Leon needs at least ${MINIMUM_REQUIRED_RAM} GB of RAM`
)
} else {
LogHelper.success(`Total RAM: ${totalRAMInGB} GB`)

View File

@ -122,6 +122,7 @@ export const LEON_FILE_PATH = path.join('leon.json')
/**
* Misc
*/
export const MINIMUM_REQUIRED_RAM = 4
export const INSTANCE_ID = fs.existsSync(LEON_FILE_PATH)
? JSON.parse(fs.readFileSync(LEON_FILE_PATH, 'utf8')).instanceID
: null

View File

@ -29,8 +29,13 @@ import {
import { LogHelper } from '@/helpers/log-helper'
import { LangHelper } from '@/helpers/lang-helper'
import { SkillDomainHelper } from '@/helpers/skill-domain-helper'
import { VOICE_CONFIG_PATH, GLOBAL_DATA_PATH } from '@/constants'
import {
MINIMUM_REQUIRED_RAM,
VOICE_CONFIG_PATH,
GLOBAL_DATA_PATH
} from '@/constants'
import { getGlobalEntitiesPath, getGlobalResolversPath } from '@/utilities'
import { SystemHelper } from '@/helpers/system-helper'
interface ObjectUnknown {
[key: string]: unknown
@ -66,8 +71,11 @@ const validateSchema = (
/**
* Pre-checking
* Ensure JSON files are correctly formatted
*
* - Ensure the system requirements are met
* - Ensure JSON files are correctly formatted
*/
const VOICE_CONFIG_SCHEMAS = {
amazon: amazonVoiceConfiguration,
'google-cloud': googleCloudVoiceConfiguration,
@ -83,6 +91,23 @@ const GLOBAL_DATA_SCHEMAS = {
;(async (): Promise<void> => {
LogHelper.title('Pre-checking')
/**
* System requirements checking
*/
LogHelper.info('Checking system requirements...')
const totalRAMInGB = Math.round(SystemHelper.getTotalRAM())
if (totalRAMInGB < MINIMUM_REQUIRED_RAM) {
LogHelper.warning(
`Total RAM: ${totalRAMInGB} GB. Leon needs at least ${MINIMUM_REQUIRED_RAM} GB of RAM. It may not work as expected.`
)
} else {
LogHelper.success(
`Minimum required RAM: ${MINIMUM_REQUIRED_RAM} GB | Total RAM: ${totalRAMInGB} GB`
)
}
/**
* Voice configuration checking
*/