88#include " llguidance.h"
99
1010struct llama_sampler_llg {
11- const struct llama_model * model;
12- const struct llama_vocab * vocab;
11+ const llama_model * model;
12+ const llama_vocab * vocab;
1313 std::string grammar_kind;
1414 std::string grammar_data;
1515 LlgTokenizer *tokenizer;
@@ -31,11 +31,11 @@ static LlgConstraint *llama_sampler_llg_new(LlgTokenizer *tokenizer,
3131 return c;
3232}
3333
34- static const char * llama_sampler_llg_name (const struct llama_sampler * /* smpl*/ ) {
34+ static const char * llama_sampler_llg_name (const llama_sampler * /* smpl*/ ) {
3535 return " llguidance" ;
3636}
3737
38- static void llama_sampler_llg_accept_impl (struct llama_sampler * smpl, llama_token token) {
38+ static void llama_sampler_llg_accept_impl (llama_sampler * smpl, llama_token token) {
3939 auto * ctx = (llama_sampler_llg *) smpl->ctx ;
4040 if (ctx->grammar ) {
4141 LlgCommitResult res;
@@ -44,7 +44,7 @@ static void llama_sampler_llg_accept_impl(struct llama_sampler * smpl, llama_tok
4444 }
4545}
4646
47- static void llama_sampler_llg_apply (struct llama_sampler * smpl, llama_token_data_array * cur_p) {
47+ static void llama_sampler_llg_apply (llama_sampler * smpl, llama_token_data_array * cur_p) {
4848 auto * ctx = (llama_sampler_llg *) smpl->ctx ;
4949 if (ctx->grammar ) {
5050 if (!ctx->has_llg_res ) {
@@ -76,7 +76,7 @@ static void llama_sampler_llg_apply(struct llama_sampler * smpl, llama_token_dat
7676 }
7777}
7878
79- static void llama_sampler_llg_reset (struct llama_sampler * smpl) {
79+ static void llama_sampler_llg_reset (llama_sampler * smpl) {
8080 auto * ctx = (llama_sampler_llg *) smpl->ctx ;
8181 if (!ctx->grammar ) {
8282 return ;
@@ -88,7 +88,7 @@ static void llama_sampler_llg_reset(struct llama_sampler * smpl) {
8888 ctx->has_llg_res = false ;
8989}
9090
91- static struct llama_sampler * llama_sampler_llg_clone (const struct llama_sampler * smpl) {
91+ static llama_sampler * llama_sampler_llg_clone (const llama_sampler * smpl) {
9292 const auto * ctx = (const llama_sampler_llg *) smpl->ctx ;
9393
9494 auto * result = llama_sampler_init_llg (ctx->model , nullptr , nullptr );
@@ -108,7 +108,7 @@ static struct llama_sampler * llama_sampler_llg_clone(const struct llama_sampler
108108 return result;
109109}
110110
111- static void llama_sampler_llg_free (struct llama_sampler * smpl) {
111+ static void llama_sampler_llg_free (llama_sampler * smpl) {
112112 const auto * ctx = (llama_sampler_llg *) smpl->ctx ;
113113
114114 if (ctx->grammar ) {
@@ -119,7 +119,7 @@ static void llama_sampler_llg_free(struct llama_sampler * smpl) {
119119 delete ctx;
120120}
121121
122- static struct llama_sampler_i llama_sampler_llg_i = {
122+ static llama_sampler_i llama_sampler_llg_i = {
123123 /* .name = */ llama_sampler_llg_name,
124124 /* .accept = */ llama_sampler_llg_accept_impl,
125125 /* .apply = */ llama_sampler_llg_apply,
@@ -135,24 +135,24 @@ static size_t llama_sampler_llg_tokenize_fn(const void *user_data,
135135 uint32_t *output_tokens,
136136 size_t output_tokens_len)
137137{
138- const struct llama_vocab *vocab = (const struct llama_vocab *)user_data;
138+ const llama_vocab *vocab = (const llama_vocab *)user_data;
139139 int r = llama_tokenize (vocab, (const char *) bytes, bytes_len,
140140 (int32_t *)output_tokens, output_tokens_len, false , true );
141141 if (r < 0 )
142142 return -r;
143143 return r;
144144}
145145
146- static LlgTokenizer *llama_sampler_llg_new_tokenizer (const struct llama_model * model) {
146+ static LlgTokenizer *llama_sampler_llg_new_tokenizer (const llama_model * model) {
147147 // TODO store the tokenizer in the model somehow
148- static const struct llama_model *model_cache;
148+ static const llama_model *model_cache;
149149 static LlgTokenizer *tokenizer_cache;
150150
151151 if (model_cache == model) {
152152 return llg_clone_tokenizer (tokenizer_cache);
153153 }
154154
155- const struct llama_vocab *vocab = llama_model_get_vocab (model);
155+ const llama_vocab *vocab = llama_model_get_vocab (model);
156156
157157 auto tok_eos = llama_vocab_eot (vocab);
158158 if (tok_eos == LLAMA_TOKEN_NULL)
@@ -226,7 +226,7 @@ static LlgTokenizer *llama_sampler_llg_new_tokenizer(const struct llama_model *
226226 return tokenizer;
227227}
228228
229- struct llama_sampler * llama_sampler_init_llg (const struct llama_model * model,
229+ llama_sampler * llama_sampler_init_llg (const llama_model * model,
230230 const char * grammar_kind, const char * grammar_data) {
231231 auto * ctx = new llama_sampler_llg;
232232
@@ -263,4 +263,4 @@ struct llama_sampler * llama_sampler_init_llg(const struct llama_model * model,
263263 };
264264}
265265
266- #endif
266+ #endif // LLAMA_USE_LLGUIDANCE
0 commit comments