Java binding - Improve error check before loading Model file (#1206)

* Javav binding - Add check for Model file be Readable.

* add todo for java binding.

---------

Co-authored-by: Feliks Zaslavskiy <feliks.zaslavskiy@optum.com>
Co-authored-by: felix <felix@zaslavskiy.net>
This commit is contained in:
Felix Zaslavskiy
2023-07-15 18:07:42 -04:00
committed by GitHub
parent cfd70b69fc
commit 1e74171a7b
4 changed files with 15 additions and 4 deletions

View File

@@ -184,11 +184,16 @@ public class LLModel implements AutoCloseable {
throw new IllegalStateException("Model file does not exist: " + modelPathAbs);
}
// Check if file is Readable
if(!Files.isReadable(modelPath)){
throw new IllegalStateException("Model file cannot be read: " + modelPathAbs);
}
// Create Model Struct. Will load dynamically the correct backend based on model type
model = library.llmodel_model_create2(modelPathAbs, "auto", error);
if(model == null) {
throw new IllegalStateException("Could not load gpt4all backend :" + error.message);
throw new IllegalStateException("Could not load, gpt4all backend returned error: " + error.message);
}
library.llmodel_loadModel(model, modelPathAbs);