ollamatokenizer

package
v0.0.21 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2025 License: Apache-2.0 Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConfigHTTP

type ConfigHTTP struct {
	BaseURL string
}

ConfigHTTP contains configuration for the HTTP client.

type HTTPClient

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

HTTPClient implements the Tokenizer interface using HTTP calls to the tokenizer service.

func (*HTTPClient) CountTokens

func (c *HTTPClient) CountTokens(ctx context.Context, modelName string, prompt string) (int, error)

CountTokens implements the Tokenizer interface using the Tokenize method.

func (*HTTPClient) OptimalModel

func (c *HTTPClient) OptimalModel(ctx context.Context, baseModel string) (string, error)

OptimalModel returns the optimal model for tokenization based on the given model. This is a client-side implementation mirroring the server's logic.

func (*HTTPClient) Tokenize

func (c *HTTPClient) Tokenize(ctx context.Context, modelName string, prompt string) ([]int, error)

Tokenize sends a tokenization request to the HTTP service.

type MockTokenizer

type MockTokenizer struct {
	FixedTokenCount int
	FixedModel      string
	CustomTokens    map[string][]int
}

MockTokenizer is a mock implementation of the Tokenizer interface.

func (MockTokenizer) CountTokens

func (m MockTokenizer) CountTokens(ctx context.Context, modelName string, prompt string) (int, error)

func (MockTokenizer) OptimalModel

func (m MockTokenizer) OptimalModel(ctx context.Context, baseModel string) (string, error)

func (MockTokenizer) Tokenize

func (m MockTokenizer) Tokenize(ctx context.Context, modelName string, prompt string) ([]int, error)

type Tokenizer

type Tokenizer interface {
	Tokenize(ctx context.Context, modelName string, prompt string) ([]int, error)
	CountTokens(ctx context.Context, modelName string, prompt string) (int, error)
	OptimalModel(ctx context.Context, baseModel string) (string, error)
}

func NewHTTPClient

func NewHTTPClient(ctx context.Context, cfg ConfigHTTP) (Tokenizer, func() error, error)

NewHTTPClient creates a new HTTP-based tokenizer client.

func WithActivityTracker

func WithActivityTracker(client Tokenizer, tracker activitytracker.ActivityTracker) Tokenizer

WithActivityTracker decorates the given Tokenizer with activity tracking

Jump to

Keyboard shortcuts

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