spec

package
v1.10.3 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 11 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 spec defines the benchmark suite format: a root directory with an optional bench.yaml (suite defaults) and any number of case directories, each holding a case.yaml plus optional attachment files.

Index

Constants

View Source
const (
	SuiteFileName  = "bench.yaml"
	CaseFileName   = "case.yaml"
	GoldenFileName = "golden.json"
)
View Source
const (
	TargetV1      = "v1"      // POST /v1/chat/completions, Bearer auth
	TargetStream  = "stream"  // POST /stream, api_key (or agent_id + PAT) in body, SSE
	TargetAnswer  = "answer"  // POST /api/answer, api_key (or agent_id + PAT) in body, JSON
	TargetWebhook = "webhook" // POST webhook URL, poll /api/task_status
)

Target names accepted in bench.yaml / case.yaml.

View Source
const (
	AttachmentsUpload = "upload" // POST /api/store_attachment, send ids (default)
	AttachmentsInline = "inline" // v1 only: base64 file content parts in the message
)

Attachment modes accepted in bench.yaml / case.yaml.

View Source
const (
	ThoughtIgnore  = "ignore"
	ThoughtPresent = "present"
	ThoughtAbsent  = "absent"
)

Values accepted by expect.stream.thought.

View Source
const (
	DefaultTimeout      = 120 * time.Second
	DefaultPollInterval = 2 * time.Second
)

Defaults applied when neither the case nor the suite sets a value.

View Source
const EnvFileName = ".env"

EnvFileName is the dotenv file consulted for ${VAR} interpolation. The suite directory's .env wins over the working directory's; real environment variables win over both — so a committed suite can reference ${KEYS} that each machine provides via its shell, a local .env, or CI secrets.

Variables

AllTargets lists the accepted target names in display order.

Functions

func AgentIDTargetError

func AgentIDTargetError(target string) error

AgentIDTargetError is the error for agent_id combined with a target that cannot use it.

func SameOrigin

func SameOrigin(a, b string) bool

SameOrigin reports whether two base URLs share scheme, host and port. The personal access token is only ever sent to the origin the user configured (--url, DOCSGPT_URL or the config file), never to one a suite file names: a bench.yaml is data, often from someone else's repository, and its base_url must not be able to collect the account token.

func TargetSupportsAgentID

func TargetSupportsAgentID(target string) bool

TargetSupportsAgentID reports whether target can address an agent by id with a personal access token. v1 authenticates with the agent API key as the Bearer credential and a webhook with the token in its URL, so neither can.

func ValidTarget

func ValidTarget(name string) bool

ValidTarget reports whether name is a known target.

Types

type AnswerExpect

type AnswerExpect struct {
	Equals      string     `yaml:"equals"`
	Contains    StringList `yaml:"contains"`     // case-insensitive substrings
	NotContains StringList `yaml:"not_contains"` // case-insensitive substrings
	Regex       StringList `yaml:"regex"`
	NotRegex    StringList `yaml:"not_regex"`
}

AnswerExpect asserts on the final answer text.

type Case

type Case struct {
	Name string `yaml:"-"` // relative dir path, set by the loader
	Dir  string `yaml:"-"` // absolute dir path, set by the loader

	Description string     `yaml:"description"`
	Tags        StringList `yaml:"tags"`
	Skip        string     `yaml:"skip"` // non-empty = skip with this reason

	Agent           string     `yaml:"agent"`
	AgentID         string     `yaml:"agent_id"` // excludes agent; overrides the suite's agent/agent_id
	Target          string     `yaml:"target"`
	Model           string     `yaml:"model"`
	Stream          *bool      `yaml:"stream"`
	AttachmentsMode string     `yaml:"attachments_mode"`
	WebhookURL      string     `yaml:"webhook_url"`
	BaseURL         string     `yaml:"base_url"`
	Question        string     `yaml:"question"`
	Turns           []Turn     `yaml:"turns"`       // multi-turn alternative to question
	Attachments     StringList `yaml:"attachments"` // filenames relative to the case dir

	Expect Expect `yaml:"expect"` // applies to the (last) answer

	Repeat  int      `yaml:"repeat"`
	MinPass int      `yaml:"min_pass"`
	Timeout Duration `yaml:"timeout"`
}

Case is one case.yaml. Zero values defer to the suite config.

func (*Case) FinalQuestion

func (c *Case) FinalQuestion() string

FinalQuestion returns the last user message (the one expect applies to).

func (*Case) GoldenPath

func (c *Case) GoldenPath() string

GoldenPath returns the case's golden file location.

func (*Case) LoadGolden

func (c *Case) LoadGolden() (*Golden, error)

LoadGolden reads the case's golden file; returns (nil, nil) if absent.

func (*Case) MultiTurn

func (c *Case) MultiTurn() bool

MultiTurn reports whether the case is defined by turns rather than question.

func (*Case) Questions

func (c *Case) Questions() []string

Questions returns the ordered user messages of the case.

func (*Case) SaveGolden

func (c *Case) SaveGolden(g *Golden) error

SaveGolden writes the case's golden file.

type Duration

type Duration time.Duration

Duration accepts "90s"/"2m" strings or bare numbers (seconds) in YAML.

func (Duration) Std

func (d Duration) Std() time.Duration

func (*Duration) UnmarshalYAML

func (d *Duration) UnmarshalYAML(node *yaml.Node) error

type Effective

type Effective struct {
	Agent           string // agent API key reference; "" when AgentID is set
	AgentID         string // agent id run with a personal access token; "" when Agent is set
	Target          string
	Model           string
	Stream          bool // v1 SSE mode
	AttachmentsMode string
	BaseURL         string
	WebhookURL      string
	Timeout         time.Duration
	PollInterval    time.Duration
	Repeat          int
	MinPass         int
}

Effective is a case's settings after suite defaults and built-in defaults.

type ErrorExpect

type ErrorExpect struct {
	Status   int        `yaml:"status"`   // HTTP status; 0 = any
	Contains StringList `yaml:"contains"` // case-insensitive substrings of the error message/body
}

ErrorExpect makes a server error the expected outcome. When present, a successful answer fails the case.

type Expect

type Expect struct {
	Answer  *AnswerExpect  `yaml:"answer"`
	JSON    map[string]any `yaml:"json"` // gjson path -> matcher (scalar or matcher map)
	Sources *SourcesExpect `yaml:"sources"`
	Tools   *ToolsExpect   `yaml:"tools"`
	Judge   *JudgeExpect   `yaml:"judge"`
	Limits  *LimitsExpect  `yaml:"limits"`
	Stream  *StreamExpect  `yaml:"stream"` // SSE integrity (stream target)
	Error   *ErrorExpect   `yaml:"error"`  // negative case: a server error is the expected outcome
	Golden  bool           `yaml:"golden"` // compare answer against golden.json (see `bench record`)
}

Expect holds the assertion sections. Every section is optional; omitted sections are skipped, mirroring the original expected.yaml behavior.

func (Expect) Empty

func (e Expect) Empty() bool

Empty reports whether no assertion section is present.

type Golden

type Golden struct {
	Answer string `json:"answer"`
}

Golden is the recorded output of a case (`bench record`), stored as golden.json in the case directory.

type JudgeAgent

type JudgeAgent struct {
	Agent       string   `yaml:"agent"`       // key name or literal API key
	BaseURL     string   `yaml:"base_url"`    // defaults to the suite base URL
	Model       string   `yaml:"model"`       // model id forwarded in the judge chat request
	Temperature *float64 `yaml:"temperature"` // sampling temperature passthrough (e.g. 0)
}

JudgeAgent identifies the agent used for LLM-as-judge grading.

type JudgeExpect

type JudgeExpect struct {
	Rubric   string   `yaml:"rubric"`
	MinScore *float64 `yaml:"min_score"` // 0..1; nil = judge.DefaultMinScore (explicit 0 is honored)
}

JudgeExpect grades the answer with a second agent (LLM-as-judge).

type LimitsExpect

type LimitsExpect struct {
	MaxSeconds           float64 `yaml:"max_seconds"`             // whole run (all turns)
	MaxFirstTokenSeconds float64 `yaml:"max_first_token_seconds"` // time to first output (stream / v1 streamed)
	MaxTotalTokens       int     `yaml:"max_total_tokens"`        // v1 target only (usage not exposed elsewhere)
}

LimitsExpect asserts performance/cost budgets.

type ModelPricing

type ModelPricing struct {
	InputPerMillion  float64 `yaml:"input_per_million" json:"input_per_million"`
	OutputPerMillion float64 `yaml:"output_per_million" json:"output_per_million"`
}

ModelPricing is the USD price per one million tokens.

type SourcesExpect

type SourcesExpect struct {
	Min *int `yaml:"min"`
	Max *int `yaml:"max"`
}

SourcesExpect asserts on the number of retrieval sources returned.

type StreamExpect

type StreamExpect struct {
	EndFrame      *bool      `yaml:"end_frame"`      // an `end` frame (or [DONE]) was observed
	ErrorFrame    *bool      `yaml:"error_frame"`    // an `error` frame was observed (only false is meaningful)
	Thought       string     `yaml:"thought"`        // present | absent | ignore (default)
	FramesContain StringList `yaml:"frames_contain"` // frame types that must appear at least once
}

StreamExpect asserts on SSE stream integrity (stream target only).

type StringList

type StringList []string

StringList accepts a single string or a list of strings in YAML.

func (*StringList) UnmarshalYAML

func (s *StringList) UnmarshalYAML(node *yaml.Node) error

type Suite

type Suite struct {
	Dir    string // absolute path of the suite root
	Name   string // base name of the root dir, used for run history
	Config SuiteConfig
	Cases  []*Case
}

Suite is a fully loaded benchmark directory.

func Load

func Load(dir string) (*Suite, error)

Load reads a suite root: optional bench.yaml plus every directory under it (recursively) that contains a case.yaml. Hidden directories are skipped.

func (*Suite) Effective

func (s *Suite) Effective(c *Case) Effective

Effective resolves case-level overrides against suite and built-in defaults.

func (*Suite) Filter

func (s *Suite) Filter(match string, tags []string) []*Case

Filter returns cases whose name or description contains match (case-insensitive) and that carry at least one of tags (when given).

func (*Suite) Validate

func (s *Suite) Validate(c *Case) error

Validate checks a case against its effective settings. It is called by the loader; callers overriding target/agent at runtime should re-validate.

type SuiteConfig

type SuiteConfig struct {
	Agent           string      `yaml:"agent"`            // key name from ~/.docsgpt/config.json, or a literal API key
	AgentID         string      `yaml:"agent_id"`         // agent id, authenticated with a personal access token (stream/answer only); excludes agent
	Target          string      `yaml:"target"`           // v1 | stream | answer | webhook
	Model           string      `yaml:"model"`            // model id sent with every request (empty = agent default)
	Stream          *bool       `yaml:"stream"`           // v1 target: SSE streaming instead of one JSON response
	AttachmentsMode string      `yaml:"attachments_mode"` // upload (default) | inline (v1 only)
	BaseURL         string      `yaml:"base_url"`         // overrides CLI config base URL
	WebhookURL      string      `yaml:"webhook_url"`      // required for target: webhook
	Judge           *JudgeAgent `yaml:"judge"`            // default judge for expect.judge sections
	Concurrency     int         `yaml:"concurrency"`      // parallel cases; default 1
	Timeout         Duration    `yaml:"timeout"`          // per-run (per-turn) timeout; default 120s
	PollInterval    Duration    `yaml:"poll_interval"`    // webhook/attachment polling; default 2s
	Repeat          int         `yaml:"repeat"`           // runs per case; default 1
	MinPass         int         `yaml:"min_pass"`         // passing runs required; default = repeat
	RunTag          string      `yaml:"run_tag"`          // sent as X-DocsGPT-Bench-Tag: bench:<tag> (see --run-tag)

	// Pricing overrides/fallbacks for the cost column, keyed by model id.
	// Used when /api/models does not expose pricing for a model.
	Pricing map[string]ModelPricing `yaml:"pricing"`
}

SuiteConfig is bench.yaml at the suite root: defaults for every case.

type ToolsExpect

type ToolsExpect struct {
	Called    StringList `yaml:"called"`
	NotCalled StringList `yaml:"not_called"`
}

ToolsExpect asserts on tool calls made by the agent.

type Turn

type Turn struct {
	Question string  `yaml:"question"`
	Expect   *Expect `yaml:"expect"` // optional per-turn assertions
}

Turn is one user message of a multi-turn case.

Jump to

Keyboard shortcuts

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