Skip to content

Commit bf90177

Browse files
committed
Add llama_sample_grammar
1 parent 1b6997d commit bf90177

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

llama_cpp/llama_cpp.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,24 @@ def llama_sample_temperature(
11571157
_lib.llama_sample_temperature.restype = None
11581158

11591159

1160+
# /// @details Apply constraints from grammar
1161+
# LLAMA_API void llama_sample_grammar(struct llama_context * ctx, llama_token_data_array * candidates, const struct llama_grammar * grammar);
1162+
def llama_sample_grammar(
1163+
ctx: llama_context_p,
1164+
candidates, # type: _Pointer[llama_token_data_array]
1165+
grammar: llama_grammar_p,
1166+
):
1167+
return _lib.llama_sample_grammar(ctx, candidates, grammar)
1168+
1169+
1170+
_lib.llama_sample_grammar.argtypes = [
1171+
llama_context_p,
1172+
llama_token_data_array_p,
1173+
llama_grammar_p,
1174+
]
1175+
_lib.llama_sample_grammar.restype = None
1176+
1177+
11601178
# @details Mirostat 1.0 algorithm described in the paper https://arxiv.org/abs/2007.14966. Uses tokens instead of words.
11611179
# @param candidates A vector of `llama_token_data` containing the candidate tokens, their probabilities (p), and log-odds (logit) for the current position in the generated text.
11621180
# @param tau The target cross-entropy (or surprise) value you want to achieve for the generated text. A higher value corresponds to more surprising or less predictable text, while a lower value corresponds to less surprising or more predictable text.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy