ollamatokenizer

package
v0.0.39 Latest Latest
Warning

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

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

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