| 37 | } |
| 38 | |
| 39 | void llama_sampling_reset(llama_sampling_context * ctx) { |
| 40 | if (ctx->grammar != NULL) { |
| 41 | llama_grammar_free(ctx->grammar); |
| 42 | ctx->grammar = NULL; |
| 43 | } |
| 44 | |
| 45 | if (!ctx->parsed_grammar.rules.empty()) { |
| 46 | std::vector<const llama_grammar_element *> grammar_rules(ctx->parsed_grammar.c_rules()); |
| 47 | |
| 48 | ctx->grammar = llama_grammar_init( |
| 49 | grammar_rules.data(), |
| 50 | grammar_rules.size(), ctx->parsed_grammar.symbol_ids.at("root")); |
| 51 | } |
| 52 | |
| 53 | std::fill(ctx->prev.begin(), ctx->prev.end(), 0); |
| 54 | ctx->cur.clear(); |
| 55 | } |
| 56 | |
| 57 | void llama_sampling_cp(llama_sampling_context * src, llama_sampling_context * dst) { |
| 58 | if (dst->grammar) { |
no test coverage detected