token

package
v0.3.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 22, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package token provides token counting utilities using tiktoken encoding.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Counter

type Counter struct {
	// contains filtered or unexported fields
}

Counter handles token counting for text and message arrays.

func NewCounter

func NewCounter() (*Counter, error)

NewCounter creates a new token counter with cl100k_base encoding.

func (*Counter) CountMessages

func (c *Counter) CountMessages(system string, messages []MessageContent) (int, error)

CountMessages counts tokens in a message array. Estimates tokens for system prompt + messages with formatting overhead.

func (*Counter) CountTokens

func (c *Counter) CountTokens(text string) (int, error)

CountTokens counts tokens in a string.

type MessageContent

type MessageContent struct {
	Role        string
	Content     string
	ExtraTokens int
}

MessageContent represents a single message in a conversation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL