models

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoMultiDispatchModels = errors.New("no models provided to multi dispatch model, it needs at least 1")

Functions

func Cache

func Cache(model jpf.Model, cache jpf.ModelResponseCache, opts ...CachedModelOpt) jpf.Model

Cache wraps a Model with response caching functionality. It stores responses in the provided ModelResponseCache implementation, returning cached results for identical input messages and salts to avoid redundant model calls.

func CountUsage

func CountUsage(model jpf.Model, counter *UsageCounter) jpf.Model

CountUsage wraps a Model with token usage tracking functionality. It aggregates token usage statistics in the provided UsageCounter, which allows monitoring total token consumption across multiple model calls.

func LimitConcurrency

func LimitConcurrency(model jpf.Model, limiter *semaphore.Weighted) jpf.Model

LimitConcurrency wraps a Model with concurrency control. It ensures that only a limited number of concurrent calls can be made to the underlying model, using the provided semaphore to manage access (this can be shared between different model instances to ensure control at any level).

func Log

func Log(model jpf.Model, logger jpf.ModelLogger) jpf.Model

Log wraps a Model with logging functionality. It logs all interactions with the model using the provided ModelLogger. Each model call is logged with input messages, output messages, usage statistics, and timing information.

func Map

func Map(model jpf.Model, f func(jpf.Message) jpf.Message) jpf.Model

func MultiDispatch

func MultiDispatch(models []jpf.Model) jpf.Model

Wrap a number of underlying models. Each model will have the same request sent to it at the same time. The fastest model to respond without error will provide the final response. If all models respond with error, the fastest erroring model will be returned. This is useful when model response times are very variable, and you don't mind paying more to increase the chance of a fast response. WARNING: It is impossible to stream through this, because we do not know which response will be returned. Streaming does not work with this model in the chain. WARNING: Becasue we send off multiple requests but only wait for one to come back, the token usage tracking is inaccurate above this model in the chain. The tokens returned by this model are the tokens of the first response. For accurate token tracking, attach the token tracker below this model in the tree.

func NewRemote

func NewRemote(format APIFormat, name string, key string, opts ...APIModelOpt) jpf.Model

func RateLimit

func RateLimit(model jpf.Model, limiter *rate.Limiter) jpf.Model

func Retry

func Retry(model jpf.Model, maxRetries int, opts ...RetryOpt) jpf.Model

Retry wraps a Model with retry functionality. If the underlying model returns an error, this wrapper will retry the operation up to a configurable number of times with an optional delay between retries.

func RetryChain

func RetryChain(models []jpf.Model) jpf.Model

RetryChain creates a Model that tries a list of models in order, returning the result from the first one that doesn't fail. If all models fail, it returns a joined error containing all the errors.

func Timeout

func Timeout(model jpf.Model, timeout time.Duration) jpf.Model

Timeout creates a new model that will cause the context of the child to timeout, a specified duration after Respond is called. Caution: It only tells the context to timeout - it will not forecfully stop the child model if it does not respect the context.

func TransformByPrefix

func TransformByPrefix(prefix string) func(string) string

func WithDelay

func WithDelay(delay time.Duration) func(*retryModel)

func WithSalt

func WithSalt(salt string) func(m *cachedModel)

Types

type APIFormat

type APIFormat uint8
const (
	OpenAI APIFormat = iota
	Google
)

type APIModelOpt

type APIModelOpt func(*apiModelSettings)

func WithHeader

func WithHeader(key, value string) APIModelOpt

func WithHeaders

func WithHeaders(headers map[string]string) APIModelOpt

func WithMaxOutput

func WithMaxOutput(n int) APIModelOpt

func WithPrediction

func WithPrediction(pred string) APIModelOpt

func WithPresencePenalty

func WithPresencePenalty(p float64) APIModelOpt

func WithReasoningEffort

func WithReasoningEffort(re ReasoningEffort) APIModelOpt

func WithTemperature

func WithTemperature(temp float64) APIModelOpt

func WithTopP

func WithTopP(tp int) APIModelOpt

func WithURL

func WithURL(u string) APIModelOpt

func WithVerbosity

func WithVerbosity(vb Verbosity) APIModelOpt

type CachedModelOpt

type CachedModelOpt func(*cachedModel)

type ReasoningEffort

type ReasoningEffort uint8
const (
	LowReasoning ReasoningEffort = iota
	MediumReasoning
	HighReasoning
	XHighReasoning
)

type RetryOpt

type RetryOpt func(*retryModel)

type UsageCounter

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

Counts up the sum usage. Is completely concurrent-safe.

func NewUsageCounter

func NewUsageCounter() *UsageCounter

NewUsageCounter creates a new UsageCounter with zero initial usage. The counter is safe for concurrent use across multiple goroutines.

func (*UsageCounter) Add

func (u *UsageCounter) Add(usage jpf.Usage)

Add the given usage to the counter.

func (*UsageCounter) Get

func (u *UsageCounter) Get() jpf.Usage

Get the current usage in the counter.

type Verbosity

type Verbosity uint8
const (
	LowVerbosity Verbosity = iota
	MediumVerbosity
	HighVerbosity
)

Jump to

Keyboard shortcuts

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