gguf.cpp : find key example

This commit is contained in:
klosax 2023-07-28 22:26:49 +02:00 committed by GitHub
parent 11ef380c2a
commit e9d2990c3d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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 // tensor info
{ {
const int n_tensors = gguf_get_n_tensors(ctx); const int n_tensors = gguf_get_n_tensors(ctx);