mirror of
https://github.com/leon-ai/leon.git
synced 2024-10-26 18:18:46 +03:00
scripts(setup-llm): kick off LLM setup and unify common functions
This commit is contained in:
parent
7482edde0a
commit
c4d2524922
2
.gitignore
vendored
2
.gitignore
vendored
@ -27,10 +27,12 @@ tcp_server/src/Pipfile.lock
|
||||
!tcp_server/**/.gitkeep
|
||||
!bridges/python/**/.gitkeep
|
||||
!bridges/nodejs/**/.gitkeep
|
||||
!core/data/models/llm/.gitkeep
|
||||
!**/*.sample*
|
||||
skills/**/src/settings.json
|
||||
skills/**/memory/*.json
|
||||
core/data/models/*.nlp
|
||||
core/data/models/llm/*
|
||||
package.json.backup
|
||||
.python-version
|
||||
schemas/**/*.json
|
||||
|
0
core/data/models/llm/.gitkeep
Normal file
0
core/data/models/llm/.gitkeep
Normal file
@ -1,12 +1,8 @@
|
||||
import fs from 'node:fs'
|
||||
import path from 'node:path'
|
||||
import stream from 'node:stream'
|
||||
import readline from 'node:readline'
|
||||
|
||||
import axios from 'axios'
|
||||
import { command } from 'execa'
|
||||
import prettyBytes from 'pretty-bytes'
|
||||
import prettyMilliseconds from 'pretty-ms'
|
||||
import extractZip from 'extract-zip'
|
||||
|
||||
import {
|
||||
@ -24,6 +20,7 @@ import {
|
||||
TCP_SERVER_VERSION
|
||||
} from '@/constants'
|
||||
import { LogHelper } from '@/helpers/log-helper'
|
||||
import { FileHelper } from '@/helpers/file-helper'
|
||||
|
||||
/**
|
||||
* Set up binaries according to the given setup target
|
||||
@ -59,16 +56,6 @@ TARGETS.set('tcp-server', {
|
||||
isPlatformDependent: true
|
||||
})
|
||||
|
||||
async function createManifestFile(manifestPath, name, version) {
|
||||
const manifest = {
|
||||
name,
|
||||
version,
|
||||
setupDate: Date.now()
|
||||
}
|
||||
|
||||
await fs.promises.writeFile(manifestPath, JSON.stringify(manifest, null, 2))
|
||||
}
|
||||
|
||||
const setupBinaries = async (key) => {
|
||||
const {
|
||||
name,
|
||||
@ -120,28 +107,7 @@ const setupBinaries = async (key) => {
|
||||
|
||||
const archiveWriter = fs.createWriteStream(archivePath)
|
||||
const latestReleaseAssetURL = `${GITHUB_URL}/releases/download/${key}_v${version}/${archiveName}`
|
||||
const { data } = await axios.get(latestReleaseAssetURL, {
|
||||
responseType: 'stream',
|
||||
onDownloadProgress: ({ loaded, total, progress, estimated, rate }) => {
|
||||
const percentage = Math.floor(progress * 100)
|
||||
const downloadedSize = prettyBytes(loaded)
|
||||
const totalSize = prettyBytes(total)
|
||||
const estimatedTime = !estimated
|
||||
? 0
|
||||
: prettyMilliseconds(estimated * 1_000, { secondsDecimalDigits: 0 })
|
||||
const downloadRate = !rate ? 0 : prettyBytes(rate)
|
||||
|
||||
readline.clearLine(process.stdout, 0)
|
||||
readline.cursorTo(process.stdout, 0, null)
|
||||
process.stdout.write(
|
||||
`Download progress: ${percentage}% (${downloadedSize}/${totalSize} | ${downloadRate}/s | ${estimatedTime} ETA)`
|
||||
)
|
||||
|
||||
if (percentage === 100) {
|
||||
process.stdout.write('\n')
|
||||
}
|
||||
}
|
||||
})
|
||||
const { data } = await FileHelper.downloadFile(latestReleaseAssetURL, 'stream')
|
||||
|
||||
data.pipe(archiveWriter)
|
||||
await stream.promises.finished(archiveWriter)
|
||||
@ -156,7 +122,7 @@ const setupBinaries = async (key) => {
|
||||
|
||||
await Promise.all([
|
||||
fs.promises.rm(archivePath, { recursive: true, force: true }),
|
||||
createManifestFile(manifestPath, name, version)
|
||||
FileHelper.createManifestFile(manifestPath, name, version)
|
||||
])
|
||||
|
||||
LogHelper.success(`${name} manifest file created`)
|
||||
|
27
scripts/setup/setup-llm.js
Normal file
27
scripts/setup/setup-llm.js
Normal file
@ -0,0 +1,27 @@
|
||||
/*import fs from 'node:fs'
|
||||
|
||||
import {
|
||||
LLM_FILE_NAME,
|
||||
LLM_PATH
|
||||
} from '@/constants'*/
|
||||
// import { LogHelper } from '@/helpers/log-helper'
|
||||
// import { FileHelper } from '@/helpers/file-helper'
|
||||
|
||||
/**
|
||||
* Download and set up LLM
|
||||
* TODO...
|
||||
* Download LLM via Helper method...
|
||||
* Create manifest via Helper method...
|
||||
*/
|
||||
|
||||
export default async () => {
|
||||
/*const canSetupLLM = await checkMinimumHardwareRequirements()
|
||||
|
||||
if (canSetupLLM) {
|
||||
|
||||
|
||||
// await setupLLM()
|
||||
} else {
|
||||
LogHelper.error('Minimum hardware requirements not met')
|
||||
}*/
|
||||
}
|
@ -8,6 +8,7 @@ import generateJSONSchemas from '../generate/generate-json-schemas'
|
||||
import setupDotenv from './setup-dotenv'
|
||||
import setupCore from './setup-core'
|
||||
import setupSkills from './setup-skills/setup-skills'
|
||||
import setupLLM from './setup-llm'
|
||||
import setupBinaries from './setup-binaries'
|
||||
import createInstanceID from './create-instance-id'
|
||||
|
||||
@ -23,6 +24,7 @@ import createInstanceID from './create-instance-id'
|
||||
await setupCore()
|
||||
await setupSkills()
|
||||
LoaderHelper.stop()
|
||||
await setupLLM()
|
||||
await setupBinaries()
|
||||
await generateHTTPAPIKey()
|
||||
await generateJSONSchemas()
|
||||
|
@ -147,6 +147,18 @@ export const SERVER_PATH = path.join(
|
||||
export const TMP_PATH = path.join(SERVER_PATH, 'tmp')
|
||||
export const LEON_FILE_PATH = path.join(process.cwd(), 'leon.json')
|
||||
|
||||
/**
|
||||
* LLMs
|
||||
*/
|
||||
export const LLM_VERSION = 'v0.2.Q4_K_S'
|
||||
export const LLM_NAME = `Mistral 7B Instruct ${LLM_VERSION}`
|
||||
export const LLM_FILE_NAME = `mistral-7b-instruct-${LLM_VERSION}.gguf`
|
||||
export const LLM_PATH = path.join(
|
||||
MODELS_PATH,
|
||||
'llm',
|
||||
LLM_FILE_NAME
|
||||
)
|
||||
|
||||
/**
|
||||
* Misc
|
||||
*/
|
||||
|
67
server/src/helpers/file-helper.ts
Normal file
67
server/src/helpers/file-helper.ts
Normal file
@ -0,0 +1,67 @@
|
||||
import readline from 'node:readline'
|
||||
import fs from 'node:fs'
|
||||
|
||||
import axios, {
|
||||
type AxiosResponse,
|
||||
type ResponseType as AxiosResponseType
|
||||
} from 'axios'
|
||||
import prettyBytes from 'pretty-bytes'
|
||||
import prettyMilliseconds from 'pretty-ms'
|
||||
|
||||
export class FileHelper {
|
||||
/**
|
||||
* Download file
|
||||
* @param fileURL The file URL to download
|
||||
* @param responseType The Axios request response type
|
||||
* @example downloadFile('https://example.com/file.zip', 'arraybuffer') // ArrayBuffer
|
||||
*/
|
||||
public static downloadFile(fileURL: string, responseType: AxiosResponseType): Promise<AxiosResponse> {
|
||||
return axios.get(fileURL, {
|
||||
responseType,
|
||||
onDownloadProgress: ({ loaded, total, progress, estimated, rate }) => {
|
||||
// TODO: remove
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-expect-error
|
||||
const percentage = Math.floor(progress * 100)
|
||||
const downloadedSize = prettyBytes(loaded)
|
||||
// TODO: remove
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-expect-error
|
||||
const totalSize = prettyBytes(total)
|
||||
const estimatedTime = !estimated
|
||||
? 0
|
||||
: prettyMilliseconds(estimated * 1_000, { secondsDecimalDigits: 0 })
|
||||
const downloadRate = !rate ? 0 : prettyBytes(rate)
|
||||
|
||||
readline.clearLine(process.stdout, 0)
|
||||
// TODO: remove
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-expect-error
|
||||
readline.cursorTo(process.stdout, 0, null)
|
||||
process.stdout.write(
|
||||
`Download progress: ${percentage}% (${downloadedSize}/${totalSize} | ${downloadRate}/s | ${estimatedTime} ETA)`
|
||||
)
|
||||
|
||||
if (percentage === 100) {
|
||||
process.stdout.write('\n')
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a manifest file
|
||||
* @param manifestPath The manifest file path
|
||||
* @param manifestName The manifest name
|
||||
* @param manifestVersion The manifest version
|
||||
*/
|
||||
public static async createManifestFile(manifestPath: string, manifestName: string, manifestVersion: string): Promise<void> {
|
||||
const manifest = {
|
||||
name: manifestName,
|
||||
version: manifestVersion,
|
||||
setupDate: Date.now()
|
||||
}
|
||||
|
||||
await fs.promises.writeFile(manifestPath, JSON.stringify(manifest, null, 2))
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user