From c5f7eadd8767aa0c394af26aedf2118c07ae0694 Mon Sep 17 00:00:00 2001 From: Michael Yang Date: Tue, 11 Jul 2023 17:07:41 -0700 Subject: [PATCH] error checking new model --- llama/llama.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/llama/llama.go b/llama/llama.go index b64acd7e..af452f97 100644 --- a/llama/llama.go +++ b/llama/llama.go @@ -123,7 +123,14 @@ func New(model string, opts api.Options) (*llama, error) { defer C.free(unsafe.Pointer(cModel)) llm.model = C.llama_load_model_from_file(cModel, params) + if llm.model == nil { + return nil, errors.New("failed to load model") + } + llm.ctx = C.llama_new_context_with_model(llm.model, params) + if llm.ctx == nil { + return nil, errors.New("failed to create context") + } // warm up the model bos := []C.llama_token{C.llama_token_bos()}