token

package
v1.0.0-alpha.7 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateRequest

func ValidateRequest(request EstimateRequest) error

func WithEstimator

func WithEstimator(ctx context.Context, estimator Estimator) context.Context

Types

type Budget

type Budget struct {
	ContextLimit    int64 `json:"context_limit,omitempty"`
	MaxOutputTokens int64 `json:"max_output_tokens,omitempty"`
	PromptLimit     int64 `json:"prompt_limit,omitempty"`
}

type Estimate

type Estimate struct {
	Provider         string `json:"provider,omitempty"`
	Model            string `json:"model"`
	InputTokens      int64  `json:"input_tokens"`
	SystemTokens     int64  `json:"system_tokens,omitempty"`
	MessageTokens    int64  `json:"message_tokens,omitempty"`
	ToolSchemaTokens int64  `json:"tool_schema_tokens,omitempty"`
	OverheadTokens   int64  `json:"overhead_tokens,omitempty"`
	ContextLimit     int64  `json:"context_limit,omitempty"`
	MaxOutputTokens  int64  `json:"max_output_tokens,omitempty"`
	RemainingTokens  int64  `json:"remaining_tokens,omitempty"`
	Source           Source `json:"source"`
	Estimated        bool   `json:"estimated"`
}

type EstimateRequest

type EstimateRequest struct {
	Provider        string            `json:"provider,omitempty"`
	Model           string            `json:"model"`
	Messages        []Message         `json:"messages"`
	Tools           []ToolSpec        `json:"tools,omitempty"`
	MaxOutputTokens int64             `json:"max_output_tokens,omitempty"`
	ContextLimit    int64             `json:"context_limit,omitempty"`
	Metadata        map[string]string `json:"metadata,omitempty"`
}

type Estimator

type Estimator interface {
	CountPromptTokens(context.Context, EstimateRequest) (Estimate, error)
}

func EstimatorFromContext

func EstimatorFromContext(ctx context.Context) (Estimator, bool)

type InputImage

type InputImage struct {
	URL      string `json:"url,omitempty"`
	Data     []byte `json:"data,omitempty"`
	MIMEType string `json:"mime_type,omitempty"`
}

type InputPart

type InputPart struct {
	Type  InputPartType `json:"type"`
	Text  string        `json:"text,omitempty"`
	Image *InputImage   `json:"image,omitempty"`
}

type InputPartType

type InputPartType string
const (
	InputPartText  InputPartType = "input_text"
	InputPartImage InputPartType = "input_image"
)

type Message

type Message struct {
	Role       string      `json:"role"`
	Content    string      `json:"content,omitempty"`
	Input      []InputPart `json:"input,omitempty"`
	Name       string      `json:"name,omitempty"`
	ToolCallID string      `json:"tool_call_id,omitempty"`
	ToolCalls  []ToolCall  `json:"tool_calls,omitempty"`
}

type Source

type Source string
const (
	SourceTiktoken  Source = "tiktoken"
	SourceClaudeAPI Source = "claude_api"
	SourceGeminiAPI Source = "gemini_api"
)

type TiktokenEstimator

type TiktokenEstimator struct {
	Encoding string
}

func NewTiktokenEstimator

func NewTiktokenEstimator() TiktokenEstimator

func (TiktokenEstimator) CountPromptTokens

func (e TiktokenEstimator) CountPromptTokens(_ context.Context, request EstimateRequest) (Estimate, error)

type ToolCall

type ToolCall struct {
	ID        string          `json:"id"`
	Name      string          `json:"name"`
	Arguments json.RawMessage `json:"arguments,omitempty"`
}

type ToolSpec

type ToolSpec struct {
	Name        string          `json:"name"`
	Description string          `json:"description,omitempty"`
	InputSchema json.RawMessage `json:"input_schema,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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