stdbifrostfx

package
v0.0.265 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 9 Imported by: ? 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

Overview

Package stdbifrostfx provides a client of Bifrost (https://docs.getbifrost.ai), an LLM gateway, so the service names a model and leaves which provider serves it to the deployment's gateway configuration. It speaks Bifrost's OpenAI-compatible API, and is the place for Bifrost's own features, such as its x-bf-* request headers.

The client asks for log probabilities rather than text: Client.FirstToken returns how likely the model finds each token it considered as the first of its answer, so callers compute decisions from them instead of asking the model for a score.

Index

Constants

View Source
const MaxCandidates = 20

MaxCandidates is how many tokens Client.FirstToken asks for; OpenAI and most compatible providers allow up to 20.

Variables

View Source
var ErrNoLogprobs = errors.New("stdbifrostfx: no logprobs")

ErrNoLogprobs reports that the model answered without log probabilities, such as when Bifrost routes it to a provider that has none.

View Source
var ErrRejected = errors.New("stdbifrostfx: rejected")

ErrRejected reports that Bifrost or the provider behind it refused a request, such as for a model it does not serve, or with a key it does not accept; sending it again fails the same way.

Functions

func Provide

func Provide() fx.Option

Provide wires the module. It needs the *http.Client of stdhttpclientfx.

Types

type Client

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

Client asks the gateway's models questions. It is safe for concurrent use.

func New

func New(cfg Config, client *http.Client) *Client

New builds the client, which sends its requests with client, such as that of stdhttpclientfx.

func (*Client) FirstToken

func (c *Client) FirstToken(ctx context.Context, prompt string) (map[string]float64, error)

FirstToken asks the model prompt for a one-token answer, without reasoning first, and returns the tokens it considered for it with their probabilities. Tokens are trimmed and lower-cased, and the probabilities of tokens that are then the same are added up.

It fails with ErrRejected when the gateway refuses the request, and with ErrNoLogprobs when the model answers without log probabilities. Its errors never quote the response body, which may quote the prompt.

func (*Client) Model

func (c *Client) Model() string

Model returns the model the client asks.

type Config

type Config struct {
	// URL is where the service reaches the gateway.
	URL string `env:"URL,required"`
	// Model is the model the gateway routes questions to, as
	// <provider>/<model> of its configuration.
	Model string `env:"MODEL,required"`
	// Timeout bounds each question, including the gateway's retries.
	Timeout time.Duration `env:"TIMEOUT" envDefault:"1m"`
}

Config configures the module, from the environment with the STDBIFROST_ prefix.

Directories

Path Synopsis
Package stdbifrosttestfx provides the stdbifrostfx client for tests, which replays the gateway's answers from recordings, in testdata/bifrost/<test name>.yaml of the test's package, so tests need no gateway, provider, or key.
Package stdbifrosttestfx provides the stdbifrostfx client for tests, which replays the gateway's answers from recordings, in testdata/bifrost/<test name>.yaml of the test's package, so tests need no gateway, provider, or key.

Jump to

Keyboard shortcuts

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