From e9d2990c3dcb3afc0d70050c7f97263d72d0f678 Mon Sep 17 00:00:00 2001 From: klosax <131523366+klosax@users.noreply.github.com> Date: Fri, 28 Jul 2023 22:26:49 +0200 Subject: [PATCH] gguf.cpp : find key example --- examples/gguf/gguf.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/examples/gguf/gguf.cpp b/examples/gguf/gguf.cpp index c3494a343..35a870a83 100644 --- a/examples/gguf/gguf.cpp +++ b/examples/gguf/gguf.cpp @@ -253,6 +253,20 @@ bool gguf_ex_read_0(const std::string & fname) { } } + // find kv string + { + char findkey[32]; + sprintf(findkey, "some.parameter.string"); + + int keyidx = gguf_find_key(ctx, findkey); + if (keyidx == -1) { + fprintf(stdout, "%s: find key: %s not found.\n", __func__, findkey); + } else { + const char * key_value = gguf_get_val_str(ctx, keyidx); + fprintf(stdout, "%s: find key: %s found, kv[%d] value = %s\n", __func__, findkey, keyidx, key_value); + } + } + // tensor info { const int n_tensors = gguf_get_n_tensors(ctx);