diff options
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | README.txt | 2 | ||||
| -rw-r--r-- | main.c | 31 |
3 files changed, 34 insertions, 0 deletions
@@ -1,3 +1,4 @@ *.o *.cgi +*.gguf deps/ diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..c45e800 --- /dev/null +++ b/README.txt @@ -0,0 +1,2 @@ +Run with no logs: GGML_LOG_LEVEL=0 ./wordbook.cgi +Run with error logs: GGML_LOG_LEVEL=error ./wordbook.cgi @@ -1,10 +1,41 @@ #include <stdio.h> +#include <stdbool.h> +#include <err.h> +#include <unistd.h> + #include "llama.h" +#define MODEL_PATH "Qwen2.5-7B-Instruct-Q4_K_M.gguf" + int main(int argc , char *argv[]) { + struct llama_model *model; + struct llama_model_params mparams; + + if (unveil(MODEL_PATH, "r") == -1) + err(1, "unveil %s failed", MODEL_PATH); + + if (unveil(NULL, NULL) == -1) + err(1, "unveil lock failed"); + + if (pledge("stdio rpath", NULL) == -1) + err(1, "initial pledge failed"); + llama_backend_init(); + mparams = llama_model_default_params(); + mparams.n_gpu_layers = 0; /* force all layers onto CPU */ + mparams.load_mode = LLAMA_LOAD_MODE_MMAP; + + model = llama_model_load_from_file(MODEL_PATH, mparams); + if (!model) + errx(1, "failed to load model from file %s", MODEL_PATH); + + /* drop rpath after loading the model */ + if (pledge("stdio", NULL) == -1) + err(1, "secondary pledge failed"); + + llama_model_free(model); llama_backend_free(); return 0; |
