initcost

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 8 Imported by: 0 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 initcost is init being up front about its cost, since it is never bounded (design 10 Q6, Q10, Q10a): what a token of its spend is worth, the estimate of the rest of a run once it has gathered, with propose in one session or in shares (design 02 §2.3.1), the yes it waits for, the one warning when the spend passes the estimate's top, and the table of what each phase spent. Spend reads in weighted tokens first, with the cost estimate beside it when prices are known.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Proceed

func Proceed(w io.Writer, e Estimate, a Ask) bool

Proceed reports whether a run goes on past e: Yes goes on, Confirm asks, and without either the run stops, naming e and a.Rerun. When it stops, for a no or a question that could not be asked, it says why on w.

func Table

func Table(rows []Row) string

Table is rows as a markdown table, with their total, the raw counts beside the weighted tokens and the cost estimate.

func Unit

func Unit(c *spend.Cache, agent string) string

Unit says what a token of a run of the adapter named agent is worth: an input token of its default model, at its cached price, or a raw token while no price is known.

func WarnPast

func WarnPast(w io.Writer, m *spend.Meter, top spend.Spend)

WarnPast makes m say once on w, as its sessions end, when what it spends from now passes top, the top of the estimate. The run goes on.

Types

type Ask

type Ask struct {
	// Yes goes on without asking (--yes).
	Yes bool
	// Confirm asks the person; nil when there is no terminal to ask on.
	Confirm func(question string) (bool, error)
	// Rerun is the command that goes on without asking.
	Rerun string
}

Ask says how a run may go on past its estimate.

type Estimate

type Estimate struct {
	// Discovery is what discovery spent.
	Discovery spend.Spend
	// Prompt and Reply are propose's prompt and reply reserve, and Sources
	// the gathered sources, in estimated tokens.
	Prompt, Reply, Sources int
	// Shares is the shares propose reads its sources in, 0 for one session.
	Shares int
	// Ratios are the factors' ranges and the runs they come from.
	Ratios spend.Ratios
	// Lo and Hi are the range, weighed.
	Lo, Hi spend.Spend
}

Estimate is what the rest of a run is expected to spend, in weighted tokens, as a range measured from past runs: propose's prompt and reply reserve, which are known, times propose's weighted-to-raw factor, plus the sources' estimated tokens times recovery's weighted-to-sources ratio. Propose in shares counts every share's prompt and the merge's, and a reply reserve for each. A one-turn session writes its whole prompt to a 1-hour cache at twice input, so both are measured, never assumed. It is never a limit.

func For

func For(c *spend.Cache, m *spend.Meter, g store.Gather, sources int) (Estimate, error)

For estimates the rest of a run from gather g, whose sources take sources estimated tokens, after discovery spent what m has counted: propose in one session, or in the shares it needs within the window m's agent states (shares.Estimate). A source larger than one share is a *shares.TooLarge, returned before anything is spent on propose.

func New

func New(c *spend.Cache, agent string, discovery spend.Spend, prompt, reply, sources int) Estimate

New estimates the rest of a run of the adapter named agent with c's prices and ratios.

func (Estimate) Line

func (e Estimate) Line() string

Line is the estimate as init prints it.

func (Estimate) Range

func (e Estimate) Range() string

Range reads like "1.9M to 5.6M tokens (about $7.60 to $23)".

type Row

type Row struct {
	Phase                      string
	Input, CachedInput, Output int64
	Weighted                   spend.Spend
}

Row is one phase's tokens, raw and Weighted.

Jump to

Keyboard shortcuts

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