Refresh list of backends by calling configureBackends() and some refactoring in installBackend
This commit is contained in:
parent
ba4dc6d1eb
commit
2e350ab607
@ -1047,28 +1047,33 @@ export default class llamacpp_extension extends AIEngine {
|
|||||||
const re = /^llama-(b\d+)-bin-(.+?)\.tar\.gz$/
|
const re = /^llama-(b\d+)-bin-(.+?)\.tar\.gz$/
|
||||||
const archiveName = await basename(path)
|
const archiveName = await basename(path)
|
||||||
|
|
||||||
let binPath: string
|
|
||||||
|
|
||||||
if ((await fs.existsSync(path)) && path.endsWith('tar.gz')) {
|
if ((await fs.existsSync(path)) && path.endsWith('tar.gz')) {
|
||||||
const match = re.exec(archiveName)
|
const match = re.exec(archiveName)
|
||||||
|
if (!match) throw new Error('Failed to parse archive name')
|
||||||
const [, version, backend] = match
|
const [, version, backend] = match
|
||||||
if (!version && !backend) {
|
if (!version && !backend) {
|
||||||
throw new Error(`Invalid backend archive name: ${archiveName}`)
|
throw new Error(`Invalid backend archive name: ${archiveName}`)
|
||||||
}
|
}
|
||||||
const backendDir = await getBackendDir(backend, version)
|
const backendDir = await getBackendDir(backend, version)
|
||||||
await invoke('decompress', { path: path, outputDir: backendDir })
|
await invoke('decompress', { path: path, outputDir: backendDir })
|
||||||
if (platformName == 'win')
|
const binPath =
|
||||||
binPath = await joinPath([
|
platformName === 'win'
|
||||||
backendDir,
|
? await joinPath([backendDir, 'build', 'bin', 'llama-server.exe'])
|
||||||
'build',
|
: await joinPath([backendDir, 'build', 'bin', 'llama-server'])
|
||||||
'bin',
|
|
||||||
'llama-server.exe',
|
|
||||||
])
|
|
||||||
else
|
|
||||||
binPath = await joinPath([backendDir, 'build', 'bin', 'llama-server'])
|
|
||||||
if (!fs.existsSync(binPath)) {
|
if (!fs.existsSync(binPath)) {
|
||||||
|
await fs.rm(backendDir)
|
||||||
throw new Error('Not a supported backend archive!')
|
throw new Error('Not a supported backend archive!')
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
await this.configureBackends()
|
||||||
|
logger.info(`Backend ${backend}/${version} installed and UI refreshed`)
|
||||||
|
} catch (e) {
|
||||||
|
logger.error('Backend installed but failed to refresh UI', e)
|
||||||
|
throw new Error(
|
||||||
|
`Backend installed but failed to refresh UI: ${String(e)}`
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user