50 const std::string& text,
bool add_special)
const
52 if (vocab_ ==
nullptr) {
return {}; }
55 int n = llama_tokenize(vocab_, text.c_str(),
56 static_cast<int32_t
>(text.size()),
57 nullptr, 0, add_special,
true);
58 if (n < 0) { n = -n; }
60 std::vector<int32_t>
tokens(
static_cast<size_t>(n));
61 int actual = llama_tokenize(vocab_, text.c_str(),
62 static_cast<int32_t
>(text.size()),
63 tokens.data(), n, add_special,
true);
65 logger->error(
"Tokenization failed for text of length {}",
69 tokens.resize(
static_cast<size_t>(actual));
87 if (vocab_ ==
nullptr) {
return {}; }
93 int n = llama_token_to_piece(
94 vocab_, token, buf,
sizeof(buf), 0,
false);
95 if (n >= 0) {
return std::string(buf,
static_cast<size_t>(n)); }
98 std::vector<char> large(
static_cast<size_t>(-n));
99 n = llama_token_to_piece(vocab_, token, large.data(),
100 static_cast<int32_t
>(large.size()),
103 ? std::string(large.data(),
static_cast<size_t>(n))
std::string detokenize(int32_t token) const override
Decode a single token id to its surface string.
std::vector< int32_t > tokenize(const std::string &text, bool add_special) const override
Encode text into token ids via the wrapped vocab.
LlamaCppTokenizer(const llama_vocab *vocab)
Construct with a borrowed vocab pointer.
Concrete llama.cpp tokenizer (v2.3.10 seam impl).
spdlog initialization and logger access.
ENTROPIC_EXPORT std::shared_ptr< spdlog::logger > get(const std::string &name)
Get or create a named logger.
Activate model on GPU (WARM → ACTIVE).
@ tokens
Gate on generated tokens since the last tool call.