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 ¶
const MaxCandidates = 20
MaxCandidates is how many tokens Client.FirstToken asks for; OpenAI and most compatible providers allow up to 20.
Variables ¶
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.
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 ¶
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 ¶
New builds the client, which sends its requests with client, such as that of stdhttpclientfx.
func (*Client) FirstToken ¶
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.
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. |