cat / 012
clone

a spreadsheet for the terminal: lotus 1-2-3 looks, google sheets keys and formulas, one go binary

cat/module-path
012 / internal / functions / remote.go
remote.go 1.7K
1package functions23import "src.rest/cat/012/internal/value"45// Some functions (JEV.*) are answered by a hosted model. The library6// never talks to the network: it describes each question as a RemoteCall7// and asks the Book for the answer, which the engine looks up in the8// workbook's RemoteSource. Until the answer arrives the cell shows9// Loading…, and the source queues the call.1011// RemoteCall is one question for the model, built from a function's12// arguments. It isn't comparable: Key identifies it by its content.13type RemoteCall struct {14 Kind string `json:"kind"` // "noul", "choice" or "score"15 State any `json:"state"`16 Instructions string `json:"instructions"`17 // Criteria depends on Kind: noul is [2]string{yes, no} (either may be18 // empty), choice is map[label]description, score is []string levels.19 Criteria any `json:"criteria"`20}2122// RemoteAnswer is the model's answer. Which fields are set depends on the23// call's Kind; Failed explains an answer that couldn't be had.24type RemoteAnswer struct {25 Noul float64 // probability of yes26 Choice string27 Score float6428 Confidence float64 // in Choice or Score, not a probability of truth29 Failed string30}3132// RemoteSource answers RemoteCalls. Lookup returns false while an answer33// isn't known, and queues the call.34type RemoteSource interface {35 Lookup(RemoteCall) (RemoteAnswer, bool)36}3738var (39 // Pending is shown while an answer is on its way.40 Pending = Value{Kind: value.Error, Str: "Loading…"}41 // ErrNoRemote means JEV functions can't run: there is no API key.42 ErrNoRemote = Value{Kind: value.Error, Str: "#N/A"}43)4445// IsPending reports whether v is waiting for a remote answer.46func IsPending(v Value) bool { return v == Pending }