Documentation
¶
Overview ¶
Package modelstage is the worker's side of every model stage: the dispatch-once protocol that each stage's handler runs. A stage keeps only the prompt it reads an item under, what that prompt quotes, and how the run's answer becomes the output.
A task's call is started once, under an idempotency key of its subject, the stage and the prompt's version. The subject is the task's item, or the prompt proposal that a prompt-proposal task drafts. The dispatch is stored on the output in the write that ends the worker's lease, and each later claim follows it until the run answers. So a waiting task holds no worker slot, and a lease that lapsed never pays for a second run. A run that failed is started again only once `tasks retry` queues its task, under a key that also names the failed dispatch, because a dispatch service may answer the old key with the failed run.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrKeepAgain = errors.New("the answer waits to be kept")
ErrKeepAgain marks a Keep error where the answer holds to its schema and a step after it failed, such as the scan of a suggestion. Where the run keeps a dispatch, the task follows that run again after its backoff, so the paid answer is kept without a second call. Where it keeps none, the output fails.
Functions ¶
func Estimate ¶
func Estimate(ctx context.Context, st *store.Store, stage string, items []store.Item, due func(r store.ItemRecords, open bool) bool, ) (int, *store.Tokens, error)
Estimate is how many of items a replay of stage would run on, as due says of each item's records and whether it holds an open task at stage. Its tokens are the median by kind of the stage's newest stored runs times that count, and nil where the stage holds no stored run.
Types ¶
type Stage ¶
type Stage struct {
// Name is the store's stage, and the capability of each of its tasks.
Name string
// Producer names the stage's outputs, whose version is the prompt's.
Producer string
// Prompt is the prompt that task's item is read under, which names the
// output. An error fails the task with no output, as a lens that this
// build holds no prompt for does.
Prompt func(task worker.Task) (prompts.Prompt, error)
// Data is what the prompt quotes of task's item. It is read only where a
// call starts. An error marked modelport.ErrRefused fails the task, and
// any other tries again after a backoff.
Data func(ctx context.Context, task worker.Task) (any, error)
// Keep fills out from the answer that a run gave to prompt on task, and
// returns the answer's fields that the answered line logs, never outsider
// text. An error fails the output, as an answer that breaks prompt's
// schema does, and `tasks retry` starts a new run. An error that wraps
// ErrKeepAgain leaves the output waiting on its dispatch instead.
Keep func(ctx context.Context, task worker.Task, prompt prompts.Prompt, answer json.RawMessage, out *server.ReportOutput) (logged []any, err error)
}
Stage is one model stage as its handler runs it.