Documentation
¶
Overview ¶
Package runner runs the calls of a measurement, whatever their kind. A kind plans the calls of its run and says how each is asked and logged. The runner estimates the run before it starts, starts no call whose worst case could take the run past its cap, asks the calls in order, bills them, and logs every answer, a JSON object a line, outside git.
Index ¶
- Constants
- Variables
- func CallKind(log []byte) string
- func Chosen[T any](all []T, config func(T) Config, names []string) ([]T, error)
- func ConfigNames() []string
- func E4[T any](all []T, config func(T) Config) []T
- func Stub(_ context.Context, st Step, _ provider.Request) (provider.Response, error)
- func Versions() (tutor, moduleKit string)
- type Asker
- type Call
- type Config
- type Done
- type End
- type Estimate
- type Head
- type Outcome
- type Reader
- type ReaderRecord
- type Records
- type Refused
- type Result
- type Run
- func (r *Run) Do(ctx context.Context, ask Asker, maxUSD float64, log io.Writer, ...) (Result, error)
- func (r *Run) Done(log []byte) (Done, error)
- func (r *Run) Estimate() Estimate
- func (r *Run) Rest(ctx context.Context, ask Asker, maxUSD float64, done Done, log io.Writer, ...) (Result, error)
- func (r *Run) RestEstimate(done Done) Estimate
- type Step
- type Usage
Constants ¶
const ( // MaxOutputTokens is the most a call may write, thinking included: the same for every // configuration, as on the board, so that they are compared under one limit. MaxOutputTokens = 16000 )
const ModuleKit = "github.com/altnovatrail/module-kit"
ModuleKit is the path of module-kit's Go module, whose verdicts the runner gives.
const NoRelease = "v0.0.0"
NoRelease is the version of a build that is no release.
const StoppedByCap = "the cap"
StoppedByCap begins the reason a run stopped when its cap stopped it, -max-usd: what it did not reach then is the limit of the runner's report.
Variables ¶
var E4Configs = []string{"opus-high", "haiku-low", "haiku-low-no-thinking"}
E4Configs are the names of the configurations a run asks unless it names others.
Functions ¶
func CallKind ¶
CallKind is the kind of call a run's log is of, as the record of the run, its first line, tells it: "" for a log that tells none, which is the judge's. A first line that is no record tells none either, and the reader of the judge's log says what is wrong with it.
func Chosen ¶
Chosen are the members of all whose configurations names names, in the order of all: the readers, judges or tutors of a kind that a run asks. A name of no configuration is a mistake, and the error says which names there are.
func ConfigNames ¶
func ConfigNames() []string
ConfigNames are the names of the configurations, in their order.
func E4 ¶
E4 are the members of all whose configurations E4Configs names: the readers, judges or tutors of a kind that a run asks by default, and those the tests of the kinds were written for.
func Stub ¶
Stub answers every call as a model that is always right would, by the markup (Call.Right), with the tokens the estimate expects of it, so that a run on it costs what the estimate says. A call without such an answer fails, and the run goes on. It asks no one: a run on it needs no key and no network.
func Versions ¶ added in v0.1.9
func Versions() (tutor, moduleKit string)
Versions are the tag of tutor's release this build is and the version of module-kit it holds, as the runner's report names them, from the build's information. A build that is no release of tutor — from a working tree, or by go run — is v0.0.0, as spec's examples of a report are, which no runner made; so is a module the build does not name.
Types ¶
type Asker ¶
Asker asks a step's request of a model: Models asks Claude, and Stub answers by the markup.
func Models ¶
Models asks the models of the steps' configurations with the key, each by the client that the adapter dial makes of it once, such as claude.Dial with the Anthropic key: the runner takes the adapter from its caller, so that a package of the library that runs its own measurement takes no SDK. A model the adapter does not call fails its call, and the run goes on.
type Call ¶
type Call interface {
// Request is the call's request, built when the run comes to the call. A call whose request
// cannot be built is not asked, and its record says so.
Request() (provider.Request, error)
// Right is the answer, in JSON, that a model which is always right would give, by the markup:
// what Stub answers. A call that has no such answer fails on the stub.
Right() (string, error)
// Record is the call's record in the log, from what the call came to.
Record(o Outcome) any
}
Call is what a kind says of a call of its run.
type Config ¶
Config is a configuration of a model that a run asks: a Claude model at an effort level, thinking or not.
func Configs ¶
func Configs() []Config
Configs are the configurations of the measurements, in their order: the three a run asks by default first (E4Configs), then the four the extended measurement adds, Haiku at medium, and the two of the cascade of a task from paper not among them yet.
func (Config) CostOf ¶ added in v0.1.49
CostOf is what a call that came back as resp costs, in US dollars: the input without the cache, the writes to the cache at the price of their lifetime — an hour's for any but 5 minutes — and the read from it, as the words' instructions are cached, and the output.
type Done ¶ added in v0.1.48
Done is what a log of a run that stopped short holds of it: how many of its steps it came to, the calls it made of them and what they cost, and how many of its bytes stay — all of them for a log that broke off, and those before its end for one that its cap or an interruption stopped.
type End ¶
End is the last record of a run's log: how the run ended.
func ReadLog ¶
ReadLog reads a run's log back: every line a record of its kind, the run's first and the end, if there is one, last. A last line cut off half written is a run that broke off as it wrote it, and the log is read without it. The kind of the run reads its records with read, which is given every record but the end, by its kind, in order; ReadLog reads the end itself and gives it, or nil when the log stops before the end: a run that broke off.
type Estimate ¶
type Estimate struct {
Calls int `json:"calls"`
USD float64 `json:"usd"`
WorstUSD float64 `json:"worst_usd"`
}
Estimate is what a run takes before it starts: the calls, what they are expected to cost, and the most they could cost, in US dollars.
type Head ¶
type Head struct {
Time time.Time
MaxUSD float64
Estimate Estimate
// Runner and ModuleKit are the versions of the build that runs (Versions), and Refused the
// samples the run refuses, as Run names them: the record of the run keeps them for the
// runner's report.
Runner, ModuleKit string
Refused []Refused
}
Head is what the runner knows of a run as it starts it, for the run's record: the time, the cap and the estimate.
type Outcome ¶
Outcome is what a call came to: the answer as the model gave it, the failure if it failed, and what the call took. A call whose request could not be built was not asked, and says so.
type Reader ¶
Reader is a configuration of the runner as a kind of reading reads with it: the configuration, the output tokens a call is expected to take, for the estimate, and whether it reads once whatever the repeats, as Opus does in the reduced matrix.
func ReadersOf ¶
ReadersOf are the readers of a kind, one for each configuration of the runner, in their order, with the output tokens the kind expects of each by its name and the names of those that read once. A configuration with no output here is a mistake of the code, and ReadersOf panics on it rather than estimate its calls at nothing or repeat it unasked.
func (Reader) Record ¶
func (rd Reader) Record() ReaderRecord
Record is the reader as the record of a run tells it.
type ReaderRecord ¶
type ReaderRecord struct {
Name string `json:"name"`
Model string `json:"model"`
Effort string `json:"effort"`
NoThinking bool `json:"no_thinking,omitempty"`
Once bool `json:"once,omitempty"`
InputUSD float64 `json:"input_usd_per_mtok"`
OutputUSD float64 `json:"output_usd_per_mtok"`
}
ReaderRecord is a reader as the record of a run tells it: its model and prices, and whether it reads once.
type Records ¶
Records are the log of a run of a kind of call read back: the run, its items, which are the sheets of the run or the pages of the workbook (ReadItems), and its calls in the order they were made, each as the kind's own record, and how the run ended, or nil when the log stops before the end.
func ReadItems ¶
ReadItems is ReadRecords for a kind whose items are records of another kind than "sheet", as the pages of the workbook are, "page": a record of the kind of item goes to the Sheets of the log, and one of the other kind has no place in it.
func ReadRecords ¶
ReadRecords reads the log of a run of a kind of call over sheets back, as ReadLog reads a log, each record into the kind's own type: the run's, which must tell that kind of call, named so in what it says, and the sheets' and the calls'. A log of another kind of call is refused, and so is a record of a kind the log has no place for.
type Refused ¶ added in v0.1.9
type Refused struct {
Set string `json:"set,omitempty"`
Sample string `json:"sample,omitempty"`
File string `json:"file"`
Reason string `json:"reason"`
Detail string `json:"detail"`
}
Refused is a sample the runner refuses, as the record of a run names it, for the runner's report: its set, for a run of several, its ID, when its file names one that can be read, its file, the reason as the protocol names it, such as REFUSAL_CHILD, and what of the sample it is, in words.
type Result ¶
type Result struct {
Calls int `json:"calls"`
SpentUSD float64 `json:"spent_usd"`
Stopped string `json:"stopped,omitempty"`
}
Result is how a run ended: the calls it made and what they cost, and why it stopped short, if it did: the cap, or an interruption.
type Run ¶
type Run struct {
Record func(h Head) any
Items []any
Steps []Step
// Refused are the samples the run refuses, which its record names; the command that plans the
// run sets them.
Refused []Refused
}
Run is a run as its kind planned it: the record that tells the run, the first line of its log, from what the runner knows as it starts; the records of its items, its sheets, which follow it; and its steps, in the order it makes them. The kind plans them repeat by repeat, so that a run cut short has the same repeats of every item. The record of a run of any kind but the judge tells its kind in a field call_kind; a log without one is the judge's (CallKind).
func (*Run) Do ¶
func (r *Run) Do(ctx context.Context, ask Asker, maxUSD float64, log io.Writer, now func() time.Time) (Result, error)
Do runs the steps in order, asking each call of ask, and logs every answer to log as it comes: the run's record first, then those of its items, one each step, and the end. Before each call it reserves the call's worst case: a call that could take what the run has spent past maxUSD is not started, and the run stops there. A context that ends stops the run too. A failed call is logged with its error and counts as an answer, and its tokens are billed; a call whose bill is not known counts at its worst. The error is a log that cannot be written: the run stops then, since an answer it cannot keep is lost. The time of the run and of its calls is that of now: time.Now in a run, whose monotonic reading times the calls, and a fixed clock in a test.
func (*Run) Done ¶ added in v0.1.48
Done reads what a log holds of this run, which stopped short, so that Rest asks the rest of it into the same log. The log must be this very run's: its record the one the run writes at the moment and with the cap the log tells; its items, byte for byte, those of the run; and every record after them that of the run's step in its place — the note itself for a note, and for a call the record its call gives again for the outcome the record holds, so that a kind whose step takes what an earlier one came to, as the assessment of an essay takes its reading, has it again. An end that tells the run stopped short, by its cap or an interruption, is dropped from what stays; a log that ended whole, one whose last line is cut off, one that broke off before its items were written and one that holds more steps than the run has are refused.
func (*Run) Rest ¶ added in v0.1.48
func (r *Run) Rest(ctx context.Context, ask Asker, maxUSD float64, done Done, log io.Writer, now func() time.Time) (Result, error)
Rest runs the steps of the run that a log of it which stopped short has not come to, as Do runs them, and appends their records and the end to log, the same log: done is what the log holds, as Done reads it, and log is the log cut to done.Size. What the log spent counts toward maxUSD, and the end tells the calls and the money of the whole run.
func (*Run) RestEstimate ¶ added in v0.1.48
RestEstimate is what the steps that done has not come to are expected to take.
type Step ¶
Step is a call of a run, in the order the run makes it: the configuration it asks, the input and output tokens the estimate expects it to take, the most input tokens it can take, for its worst case, and the call. How big a request can grow is the kind's to say: a request of the judge comes to about 4 000 tokens at most, and another kind's, with more pictures or a longer text, to more. A step that another call stands for, as form D of the judge stands on form B on a sheet without frames, has no call: the run writes its Note in its place in the log, and asks nothing.
func (Step) Worst ¶
Worst is the most the step's call can cost: its most input tokens, or the expected ones if the kind gave fewer, each at the higher of the input's price and that of a write to the cache for 5 minutes, which a request that caches its instructions pays for them on a miss, and the most a call may write.
type Usage ¶
type Usage struct {
ModelID string `json:"model_id,omitempty"`
InputTokens int64 `json:"input_tokens,omitempty"`
// CacheWriteTokens and CacheReadTokens are the input written to the cache, of every lifetime, and
// read from it, beside InputTokens, which holds the input without them.
CacheWriteTokens int64 `json:"cache_write_tokens,omitempty"`
CacheReadTokens int64 `json:"cache_read_tokens,omitempty"`
OutputTokens int64 `json:"output_tokens,omitempty"`
ThinkingTokens int64 `json:"thinking_tokens,omitempty"`
FirstTokenMs int64 `json:"first_token_ms,omitempty"`
Retries int `json:"retries,omitempty"`
LatencyMs int64 `json:"latency_ms,omitempty"`
CostUSD float64 `json:"cost_usd,omitempty"`
}
Usage is what a call took, under the names a kind's record of it gives them in the log: the model that answered, the tokens and the thinking, the time to the first token, the retries of the SDK, the time of the call and its cost.