feat: auto unload models on model start

This commit is contained in:
Louis 2025-06-23 22:16:34 +07:00
parent 0cbf35dc77
commit b538d57207
No known key found for this signature in database
GPG Key ID: 44FA9F4D33C37DE2

View File

@ -426,6 +426,13 @@ export default class llamacpp_extension extends AIEngine {
if (sInfo) {
throw new Error('Model already loaded!!')
}
const loadedModels = await this.getLoadedModels()
if (loadedModels.length > 0 && this.autoUnload) {
// Unload all other models if auto-unload is enabled
await Promise.all(
loadedModels.map((loadedModel) => this.unload(loadedModel))
)
}
const args: string[] = []
const cfg = this.config
const [version, backend] = cfg.version_backend.split('/')
@ -733,7 +740,9 @@ export default class llamacpp_extension extends AIEngine {
if (!response.ok) {
const errorData = await response.json().catch(() => null)
throw new Error(
`API request failed with status ${response.status}: ${JSON.stringify(errorData)}`
`API request failed with status ${response.status}: ${JSON.stringify(
errorData
)}`
)
}
const responseData = await response.json()