Documentation
¶
Overview ¶
Package ollamatokenizer provides a simple interface to ollama's internal tokenization functionality.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotImplemented = fmt.Errorf("not implemented")
ErrNotImplemented is returned when a request uses options that this library does not support.
Functions ¶
This section is empty.
Types ¶
type Tokenizer ¶
type Tokenizer struct {
// contains filtered or unexported fields
}
Tokenizer wraps an Ollama tokenizer for a specific model.
func New ¶
New creates a Tokenizer for the given model name (e.g. "llama3.2:3b"). The model must have been pulled via `ollama pull`. https://github.com/ollama/ollama/blob/v0.20.7/llm/server.go#L144-L164
func (*Tokenizer) Tokenize ¶
Tokenize encodes text into token IDs without applying any chat template. addSpecial: prepend BOS/append EOS if the model's vocab requires it (AddBOS/AddEOS GGUF metadata). parseSpecial: parse special token strings in text (e.g. <|im_start|>) into token IDs. https://github.com/ollama/ollama/blob/v0.20.7/runner/ollamarunner/runner.go#L246 https://github.com/ollama/ollama/blob/v0.20.7/runner/llamarunner/runner.go#L211
func (*Tokenizer) TokenizeChat ¶
func (t *Tokenizer) TokenizeChat(req api.ChatRequest) ([]int32, error)
TokenizeChat tokenizes messages matching /api/chat. Note: the server's chatPrompt performs context-length truncation that we do not replicate; for prompts within the context window, the rendered output is identical.
https://github.com/ollama/ollama/blob/v0.20.7/server/routes.go#L2276-L2347
func (*Tokenizer) TokenizeGenerate ¶
func (t *Tokenizer) TokenizeGenerate(req api.GenerateRequest) ([]int32, error)
TokenizeGenerate tokenizes a prompt matching /api/generate. Note: the server's chatPrompt performs context-length truncation that we do not replicate; for prompts within the context window, the rendered output is identical.
Unsupported options (return ErrNotImplemented): Suffix, Template, Raw, Context, Images.
https://github.com/ollama/ollama/blob/v0.20.7/server/routes.go#L456-L503