From dd22010e85265ae840c76ec835d67a29ed852722 Mon Sep 17 00:00:00 2001 From: Andrei Betlen Date: Thu, 22 Feb 2024 00:09:45 -0500 Subject: [PATCH] fix: Raise exceptions when llama model or context fails to load --- llama_cpp/_internals.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/llama_cpp/_internals.py b/llama_cpp/_internals.py index 10c1a6f..8690843 100644 --- a/llama_cpp/_internals.py +++ b/llama_cpp/_internals.py @@ -51,6 +51,9 @@ class _LlamaModel: self.path_model.encode("utf-8"), self.params ) + if self.model is None: + raise ValueError(f"Failed to load model from file: {path_model}") + def __del__(self): if self.model is not None and self._llama_free_model is not None: self._llama_free_model(self.model) @@ -258,6 +261,9 @@ class _LlamaContext: self.model.model, self.params ) + if self.ctx is None: + raise ValueError("Failed to create llama_context") + def __del__(self): if self.ctx is not None and self._llama_free is not None: self._llama_free(self.ctx)