provider

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const ProviderModelSeparator = "/"

ProviderModelSeparator is the the separator between a provider and a model.

Variables

View Source
var Providers = map[string]Provider{}

Providers holds a register of all providers.

Functions

func Register

func Register(provider Provider)

Register adds a provider to the common provider list.

Types

type GenerationInfo added in v1.0.8

type GenerationInfo struct {
	ID                     string  `json:"id"`
	TotalCost              float64 `json:"total_cost"`
	TokensPrompt           int     `json:"tokens_prompt"`
	TokensCompletion       int     `json:"tokens_completion"`
	NativeTokensPrompt     int     `json:"native_tokens_prompt"`
	NativeTokensCompletion int     `json:"native_tokens_completion"`
	NativeTokensReasoning  int     `json:"native_tokens_reasoning"`
}

GenerationInfo holds information about a generation. See https://openrouter.ai/docs/api-reference/overview#querying-cost-and-stats for more details.

type InjectToken

type InjectToken interface {
	// SetToken sets an access token to be used to authenticate a remote API.
	SetToken(token string)
}

InjectToken is a provider that needs an access token to authenticate a remote API.

type Loader added in v0.5.0

type Loader interface {
	// Load loads the given model.
	Load(modelIdentifier string) (err error)
	// Unload unloads the given model.
	Unload(modelIdentifier string) (err error)
}

Loader is a provider that is able to load and unload models.

type Provider

type Provider interface {
	// Available checks if the provider is ready to be used.
	// This might include checking for an installation or making sure an API access token is valid.
	Available(logger *log.Logger) (err error)
	// ID returns the unique ID of this provider.
	ID() (id string)
	// Models returns which models are available to be queried via this provider.
	Models() (models []model.Model, err error)
}

Provider defines a provider to query models such as LLMs.

type Puller added in v0.6.0

type Puller interface {
	// Pull downloads the given model.
	Pull(logger *log.Logger, modelIdentifier string) (err error)
}

Puller is a provider that is capable of pulling models.

type Query added in v0.5.0

type Query interface {
	// Query queries the provider with the given model name.
	Query(ctx context.Context, model model.Model, promptText string) (result *QueryResult, err error)
}

Query is a provider that allows to query a model directly.

type QueryResult added in v1.0.7

type QueryResult struct {
	// ResponseID holds the response ID.
	ResponseID string
	// Message holds the response message.
	Message string
	// Duration holds the duration of the result.
	Duration time.Duration
	// Usage holds the usage metrics of the query.
	Usage openai.Usage
	// GenerationInfo holds information about a generation.
	GenerationInfo *GenerationInfo
}

QueryResult holds the result of a query.

type Service added in v0.5.0

type Service interface {
	// Start starts necessary background services to use this provider and returns a shutdown function.
	Start(logger *log.Logger) (shutdown func() (err error), err error)
}

Service is a provider that requires background services.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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