eval

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: Apache-2.0 Imports: 23 Imported by: 1 module, 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 eval measures the Slack extractor: an oracle reads a conversation and writes the viewer's briefing, a blind reader writes the same briefing from the extractor's ledger alone, and a judge with the conversation compares them.

Index

Constants

View Source
const (
	SplitDev     = "dev"
	SplitHoldout = "holdout"
)
View Source
const (
	ExtractorCallUSD = 0.5
	JudgeCallUSD     = 1.0
)

Per-call caps: every call carries one, and the run's budget reserves it before the call starts.

View Source
const DefaultNow = "2026-10-21T21:00:00-03:00"

DefaultNow is the "now" of a fixture that names none: when the first fixtures were measured.

View Source
const OptimizeCallUSD = 5.0

OptimizeCallUSD caps the optimizer's call.

Variables

View Source
var Causes = []string{"missing_item", "spurious_item", "wrong_assignee", "wrong_waiting_on", "wrong_state", "wrong_resolution",
	"missing_link", "vague_summary", "missing_context", "wrong_verdict", "other"}

Causes are the ledger root causes a judge may name.

View Source
var ErrBudget = errors.New("the run stopped before passing --max-usd")
View Source
var Placeholders = []string{"{{VIEWER_ID}}", "{{VIEWER_NAME}}", "{{NOW}}", "{{LANGUAGE}}", "{{LEDGER}}", "{{CITED}}", "{{CONTEXTS}}", "{{CONVERSATION}}"}

Placeholders are the extractor template's, each exactly once.

Functions

func BlindPrompt

func BlindPrompt(base map[string]string, toolOutput string) string

BlindPrompt asks for the viewer's briefing from the tool's output alone.

func CheckTemplate

func CheckTemplate(t string) error

CheckTemplate refuses a template over the word cap or that drops or repeats a placeholder.

func ExtractorPrompt

func ExtractorPrompt(tmpl string, in extract.Input) (string, error)

ExtractorPrompt fills tmpl for in exactly as extract.Prompt fills the shipped template; "" is the shipped template itself.

func JudgePrompt

func JudgePrompt(base map[string]string, conversation string, reference, blind json.RawMessage, toolOutput string) string

JudgePrompt asks to compare the blind briefing with the reference.

func LedgerView

func LedgerView(f Fixture, r extract.Result, names map[string]string, now time.Time) string

LedgerView is what the tool shows the viewer about f: the extracted items with names, never the messages.

func Optimize

func Optimize(ctx context.Context, o OptimizeOptions) (changelog []string, cost float64, err error)

Optimize asks for a better template from the label's dev judgments alone and writes it to New, with its changelog beside it, only when it passes CheckTemplate.

func OraclePrompt

func OraclePrompt(base map[string]string, conversation string) string

OraclePrompt asks for the briefing of someone who read the conversation.

func Plain

func Plain(in extract.Input) extract.Input

Plain is in without context, segment or focus: what the oracle and the judge read.

Types

type ExportOptions

type ExportOptions struct {
	DB       *store.SlackStore
	Facts    slack.FactsReader
	Segments slack.Segments // nil leaves every DM unsegmented
	// Since and Until bound the activity: a unit with a message in [Since, Until).
	Since, Until time.Time
	Out          string
	Exclude      []string // fixtures directories; a unit sharing any (channel, message ts) with one of their fixtures is skipped
	Now          time.Time
	// Before reads the newest n messages of a conversation anchored before a ts; nil exports no context.
	Before                        func(ctx context.Context, conv, before string, n int) ([]slack.Message, error)
	ContextMessages, ContextChars int
}

type ExportReport

type ExportReport struct {
	Written, Excluded, Unsegmented int
}

func Export

Export writes one holdout fixture per Slack unit with activity in the window, users.json and viewer.json.

type Fixture

type Fixture struct {
	ID          string `json:"id"`
	Kind        string `json:"kind"`
	Split       string `json:"split,omitempty"`
	Now         string `json:"now,omitempty"`
	ChannelID   string `json:"channel_id"`
	ChannelName string `json:"channel_name"`
	ChannelType string `json:"channel_type"`
	Permalink   string `json:"permalink"`
	FocusTS     string `json:"focus_ts"`
	// Context are the messages before a DM segment, shown to the extractor only, read only.
	Context  []Message `json:"context,omitempty"`
	Messages []Message `json:"messages"`
}

func (Fixture) Input

func (f Fixture) Input(v extract.Viewer, names map[string]string, now time.Time, language string) extract.Input

Input is the extractor's input for f: an empty ledger, no segments and no window, so Render shows the whole fixture; a DM segment's context, bounds and focus are marked.

func (Fixture) NowAt

func (f Fixture) NowAt(override string) (time.Time, error)

NowAt is the fixture's now, overridden by override when set.

func (Fixture) Root

func (f Fixture) Root() string

Root is the ts the conversation hangs from: its first message's thread, or its own ts.

func (Fixture) SplitOf

func (f Fixture) SplitOf() string

SplitOf is the fixture's split: its own, else holdout when the two-digit prefix of its id is divisible by 3.

type Judgment

type Judgment struct {
	SameActions      bool               `json:"same_actions"`
	Severity         string             `json:"severity"`
	Sections         map[string]Section `json:"sections"`
	ReferenceErrors  []string           `json:"reference_errors"`
	LedgerRootCauses []RootCause        `json:"ledger_root_causes"`
	PromptFixHints   []string           `json:"prompt_fix_hints"`
}

type Key

type Key struct {
	Tier      string `json:"tier"`
	Language  string `json:"language"`
	Now       string `json:"now"`
	PromptSHA string `json:"prompt_sha"`
}

Key says what produced a stage file; a cached file is reused only under the same key.

type Message

type Message struct {
	TS         string     `json:"ts"`
	ThreadTS   string     `json:"thread_ts"`
	UserID     string     `json:"user_id"`
	UserName   string     `json:"user_name"`
	IsBot      bool       `json:"is_bot"`
	AppName    string     `json:"app_name"`
	Text       string     `json:"text"`
	Reactions  []Reaction `json:"reactions"`
	ReplyCount int        `json:"reply_count"`
	Edited     bool       `json:"edited"`
	Files      []string   `json:"files,omitempty"`
}

type OptimizeOptions

type OptimizeOptions struct {
	Asker   host.Asker
	Out     string
	Label   string
	Current string // the template the label ran with
	New     string // where the candidate goes
	Tier    host.Tier
	// Prompts are the shipped extraction prompts, whose schema the candidate keeps.
	Prompts *extract.Prompts
}

type Options

type Options struct {
	Asker    host.Asker
	Set      Set
	Out      string
	Label    string
	Split    string // dev, holdout or all ("" is all)
	Template string // the extractor's prompt template; "" is the shipped one
	// Prompts are the shipped extraction prompts.
	Prompts  *extract.Prompts
	Viewer   extract.Viewer
	Language string
	Now      string // RFC3339, overrides every fixture's now
	MaxUSD   float64
	Jobs     int

	ExtractorTier, JudgeTier host.Tier
	// EscalateOverChars sends an extraction whose conversation renders longer to the frontier tier; 0 never.
	EscalateOverChars int
	Log               io.Writer
}

type PassUsage

type PassUsage struct {
	Conversations  int   `json:"conversations"`
	TokensReported int   `json:"tokens_reported"`
	Total          Usage `json:"total"`
	Mean           Usage `json:"mean"`
}

PassUsage is what one pass spent on the conversations it answered; the token means are over the calls that reported tokens.

type Reaction

type Reaction struct {
	Name  string   `json:"name"`
	Users []string `json:"users"`
}

type Report

type Report struct {
	SpentUSD float64
	Judged   int
	Failed   int
	Score    Score
}

func Run

func Run(ctx context.Context, o Options) (Report, error)

Run writes every stage of every selected fixture under Out, then the label's score. It refuses before any call when a cached file has another key, and stops starting calls before the spend would pass MaxUSD.

type RootCause

type RootCause struct {
	Cause  string `json:"cause"`
	Detail string `json:"detail"`
}

type Score

type Score map[string]SplitScore

Score is by split, "dev" and "holdout".

func WriteScore

func WriteScore(out, label string) (Score, error)

WriteScore scores label's judgments under out against the run's manifest and writes <out>/<label>/score.json.

func (Score) Bar

func (s Score) Bar(bar float64) error

Bar fails unless the holdout is complete, has no critical or major failure, and reaches bar.

type Section

type Section struct {
	ReferenceCount int      `json:"reference_count"`
	Matched        int      `json:"matched"`
	Missed         []string `json:"missed"`
	Extra          []string `json:"extra"`
	Contradicted   []string `json:"contradicted"`
}

type Set

type Set struct {
	Fixtures []Fixture
	Users    map[string]string
	Viewer   extract.Viewer
}

Set is a fixtures directory: its fixtures by id, the user names of users.json and the viewer of viewer.json, when present.

func Load

func Load(dir string) (Set, error)

Load reads every <id>.json of dir but users.json and viewer.json; the file name is the fixture's id, whatever its id field says.

type SplitScore

type SplitScore struct {
	N               int                `json:"n"`
	Expected        int                `json:"expected"`
	SameActions     float64            `json:"same_actions"`
	CriticalOrMajor int                `json:"critical_or_major"`
	Recall          map[string]float64 `json:"recall"`
	Contradictions  int                `json:"contradictions"`
	Extras          int                `json:"extras"`
	Causes          map[string]int     `json:"causes"`
	CostUSD         float64            `json:"cost_usd"`
	Extractor       PassUsage          `json:"extractor"`
}

func ScoreSplit

func ScoreSplit(js []Judgment, expected int) SplitScore

ScoreSplit scores the judgments present of a split of expected fixtures; a missing one counts as a critical failure with different actions.

type StaleError

type StaleError struct{ Path string }

StaleError is a stage file whose key differs from the call's.

func (*StaleError) Error

func (e *StaleError) Error() string

type Usage

type Usage struct {
	CostUSD float64 `json:"cost_usd"`
	Tokens  float64 `json:"tokens"`
}

Usage is a pass's cost and tokens; the host's agent reports a call's tokens as one total.

Jump to

Keyboard shortcuts

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