ggml.c : add gguf_find_key
This commit is contained in:
parent
78f57ffd90
commit
765fab636a
1 changed files with 15 additions and 0 deletions
15
ggml.c
15
ggml.c
|
@ -18745,6 +18745,21 @@ int gguf_get_n_kv(struct gguf_context * ctx) {
|
||||||
return ctx->header.n_kv;
|
return ctx->header.n_kv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int gguf_find_key(struct gguf_context * ctx, const char * key) {
|
||||||
|
// return -1 if key not found
|
||||||
|
const int n_kv = gguf_get_n_kv(ctx);
|
||||||
|
int keyfound = -1;
|
||||||
|
|
||||||
|
for (int i = 0; i < n_kv; ++i) {
|
||||||
|
if (strcmp(key, gguf_get_key(ctx, i)) == 0) {
|
||||||
|
keyfound = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return keyfound;
|
||||||
|
}
|
||||||
|
|
||||||
const char * gguf_get_key(struct gguf_context * ctx, int i) {
|
const char * gguf_get_key(struct gguf_context * ctx, int i) {
|
||||||
return ctx->header.kv[i].key.data;
|
return ctx->header.kv[i].key.data;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue