You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// @param tokens The tokens pointer must be large enough to hold the resulting tokens.
879
907
/// @return Returns the number of tokens on success, no more than n_tokens_max
880
908
/// @return Returns a negative number on failure - the number of tokens that would have been returned
909
+
/// @param add_special Allow to add BOS and EOS tokens if model is configured to do so.
881
910
/// @param parse_special Allow tokenizing special and/or control tokens which otherwise are not exposed and treated
882
911
/// as plaintext. Does not insert a leading space.
883
912
LLAMA_API int32_tllama_tokenize(
@@ -892,15 +921,31 @@ extern "C" {
892
921
// Token Id -> Piece.
893
922
// Uses the vocabulary in the provided context.
894
923
// Does not write null terminator to the buffer.
895
-
// User code is responsible to remove the leading whitespace of the first non-BOS token when decoding multiple tokens.
924
+
// User can skip up to 'lstrip' leading spaces before copying (useful when encoding/decoding multiple tokens with 'add_space_prefix')
896
925
// @param special If true, special tokens are rendered in the output.
897
926
LLAMA_API int32_tllama_token_to_piece(
898
927
conststructllama_model * model,
899
928
llama_token token,
900
929
char * buf,
901
930
int32_t length,
931
+
int32_t lstrip,
902
932
bool special);
903
933
934
+
/// @details Convert the provided tokens into text (inverse of llama_tokenize()).
935
+
/// @param text The char pointer must be large enough to hold the resulting text.
936
+
/// @return Returns the number of chars/bytes on success, no more than text_len_max.
937
+
/// @return Returns a negative number on failure - the number of chars/bytes that would have been returned.
938
+
/// @param remove_special Allow to remove BOS and EOS tokens if model is configured to do so.
939
+
/// @param unparse_special If true, special tokens are rendered in the output.
940
+
LLAMA_API int32_tllama_detokenize(
941
+
conststructllama_model * model,
942
+
const llama_token * tokens,
943
+
int32_t n_tokens,
944
+
char * text,
945
+
int32_t text_len_max,
946
+
bool remove_special,
947
+
bool unparse_special);
948
+
904
949
/// Apply chat template. Inspired by hf apply_chat_template() on python.
905
950
/// Both "model" and "custom_template" are optional, but at least one is required. "custom_template" has higher precedence than "model"
906
951
/// NOTE: This function does not use a jinja parser. It only support a pre-defined list of template. See more: https://github.com/ggerganov/llama.cpp/wiki/Templates-supported-by-llama_chat_apply_template
@@ -924,6 +969,12 @@ extern "C" {
924
969
// Grammar
925
970
//
926
971
972
+
/// Initialize a llama_grammar.
973
+
///
974
+
/// @param rules The rule elements of the grammar to initialize.
975
+
/// @param n_rules The number of rules.
976
+
/// @param start_rule_index The index of the root rule (the starting point of the grammar).
977
+
/// @return The initialized llama_grammar or nullptr if initialization failed.
0 commit comments