Documentation
¶
Overview ¶
Package ollamatokenizer links ollama's bundled libllama.so and uses llama.cpp's real tokenizer with vocab-only model loading. The llama.cpp version must match the ollama build (ABI: llama_model_params); pin via go.mod → LLAMA_CPP_VERSION. Build inputs (populated by `make fetch-deps`) live under llama-cpp/:
- include/llama.h, ggml/include/*.h (headers)
- lib/lib{llama,ggml,ggml-base}.so (from the ollama install)
Package ollamatokenizer exposes ollama's tokenization without loading model weights, by linking ollama's bundled libllama.so and loading each GGUF vocab-only. Token IDs are byte-identical to a running ollama server.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotImplemented = fmt.Errorf("not implemented")
Functions ¶
This section is empty.
Types ¶
type ChatMessage ¶ added in v0.31.2
ChatMessage is a {role, content} pair for RenderChatJinja.
type Tokenizer ¶
type Tokenizer struct {
// contains filtered or unexported fields
}
Tokenizer holds a vocab-only GGUF handle and ollama model metadata.
func New ¶
New loads a model's vocab-only GGUF via cgo and ollama metadata via server.GetModel. https://github.com/ollama/ollama/blob/v0.31.2/server/images.go#L641
func (*Tokenizer) Tokenize ¶
Tokenize encodes text via llama_tokenize. addSpecial applies BOS/EOS per the vocab; parseSpecial parses special-token strings (e.g. <|im_start|>).
func (*Tokenizer) TokenizeChat ¶
func (t *Tokenizer) TokenizeChat(req api.ChatRequest) ([]int32, error)
TokenizeChat mirrors /api/chat's prompt assembly (no context truncation). https://github.com/ollama/ollama/blob/v0.31.2/server/routes.go#L2661-L2705
func (*Tokenizer) TokenizeGenerate ¶
func (t *Tokenizer) TokenizeGenerate(req api.GenerateRequest) ([]int32, error)
TokenizeGenerate mirrors /api/generate's prompt assembly (no context truncation). Unsupported (ErrNotImplemented): Suffix, Template, Raw, Context, Images. https://github.com/ollama/ollama/blob/v0.31.2/server/routes.go#L510-L620