summaryrefslogtreecommitdiff
path: root/llama.h
diff options
context:
space:
mode:
authorClint Herron <hanclinto@gmail.com>2024-04-04 03:44:28 -0400
committerGitHub <noreply@github.com>2024-04-04 10:44:28 +0300
commit9b84ae1806cded4d6683c7b810925da5ead40607 (patch)
tree608fa8160885c5c7571c8bd400fa59d9a2ee7e78 /llama.h
parent4399f13fb9462cd06f3f154d0aee738425000fea (diff)
examples : add GBNF validator program (#5948)
* Revising GBNF validator program to be much simpler. * Changing from streams to using cstdio * Adding final newline character.
Diffstat (limited to 'llama.h')
-rw-r--r--llama.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/llama.h b/llama.h
index f061d014..036b3268 100644
--- a/llama.h
+++ b/llama.h
@@ -1007,10 +1007,38 @@ extern "C" {
struct ggml_tensor;
+struct llama_partial_utf8 {
+ uint32_t value; // bit value so far (unshifted)
+ int n_remain; // num bytes remaining; -1 indicates invalid sequence
+};
+
+struct llama_grammar {
+ const std::vector<std::vector<llama_grammar_element>> rules;
+ std::vector<std::vector<const llama_grammar_element *>> stacks;
+
+ // buffer for partially generated UTF-8 sequence from accepted tokens
+ llama_partial_utf8 partial_utf8;
+};
+
+struct llama_grammar_candidate {
+ size_t index;
+ const uint32_t * code_points;
+ llama_partial_utf8 partial_utf8;
+};
+
const std::vector<std::pair<std::string, struct ggml_tensor *>> & llama_internal_get_tensor_map(
struct llama_context * ctx
);
+std::vector<std::vector<const llama_grammar_element *>> llama_grammar_accept(
+ const std::vector<std::vector<llama_grammar_element>> & rules,
+ const std::vector<std::vector<const llama_grammar_element *>> & stacks,
+ const uint32_t chr);
+
+std::pair<std::vector<uint32_t>, llama_partial_utf8> decode_utf8(
+ const std::string & src,
+ llama_partial_utf8 partial_start);
+
#endif // LLAMA_API_INTERNAL
#endif // LLAMA_H