Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

Refresh list of backends by calling configureBackends() and some refactoring in installBackend

Akarshan2e350ab60735
diff --git a/extensions/llamacpp-extension/src/index.ts b/extensions/llamacpp-extension/src/index.ts
index 0aaea615d..238c08ad4 100644
--- a/extensions/llamacpp-extension/src/index.ts
+++ b/extensions/llamacpp-extension/src/index.ts
@@ -1047,28 +1047,33 @@ export default class llamacpp_extension extends AIEngine {
const re = /^llama-(b\d+)-bin-(.+?)\.tar\.gz$/
const archiveName = await basename(path)
- let binPath: string
-
if ((await fs.existsSync(path)) && path.endsWith('tar.gz')) {
const match = re.exec(archiveName)
+ if (!match) throw new Error('Failed to parse archive name')
const [, version, backend] = match
if (!version && !backend) {
throw new Error(`Invalid backend archive name: ${archiveName}`)
}
const backendDir = await getBackendDir(backend, version)
await invoke('decompress', { path: path, outputDir: backendDir })
- if (platformName == 'win')
- binPath = await joinPath([
- backendDir,
- 'build',
- 'bin',
- 'llama-server.exe',
- ])
- else
- binPath = await joinPath([backendDir, 'build', 'bin', 'llama-server'])
+ const binPath =
+ platformName === 'win'
+ ? await joinPath([backendDir, 'build', 'bin', 'llama-server.exe'])
+ : await joinPath([backendDir, 'build', 'bin', 'llama-server'])
+
if (!fs.existsSync(binPath)) {
+ await fs.rm(backendDir)
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)}`
+ )
+ }
}
}