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
- Variables
- func AgentIDTargetError(target string) error
- func SameOrigin(a, b string) bool
- func TargetSupportsAgentID(target string) bool
- func ValidTarget(name string) bool
- type AnswerExpect
- type Case
- type Duration
- type Effective
- type ErrorExpect
- type Expect
- type Golden
- type JudgeAgent
- type JudgeExpect
- type LimitsExpect
- type ModelPricing
- type SourcesExpect
- type StreamExpect
- type StringList
- type Suite
- type SuiteConfig
- type ToolsExpect
- type Turn
Constants ¶
const ( SuiteFileName = "bench.yaml" CaseFileName = "case.yaml" GoldenFileName = "golden.json" )
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.
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.
const ( ThoughtIgnore = "ignore" ThoughtPresent = "present" ThoughtAbsent = "absent" )
Values accepted by expect.stream.thought.
const ( DefaultTimeout = 120 * time.Second DefaultPollInterval = 2 * time.Second )
Defaults applied when neither the case nor the suite sets a value.
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 ¶
var AllTargets = []string{TargetV1, TargetStream, TargetAnswer, TargetWebhook}
AllTargets lists the accepted target names in display order.
Functions ¶
func AgentIDTargetError ¶
AgentIDTargetError is the error for agent_id combined with a target that cannot use it.
func SameOrigin ¶
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 ¶
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 ¶
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 ¶
FinalQuestion returns the last user message (the one expect applies to).
func (*Case) GoldenPath ¶
GoldenPath returns the case's golden file location.
func (*Case) LoadGolden ¶
LoadGolden reads the case's golden file; returns (nil, nil) if absent.
func (*Case) MultiTurn ¶
MultiTurn reports whether the case is defined by turns rather than question.
func (*Case) SaveGolden ¶
SaveGolden writes the case's golden file.
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.
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 ¶
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 ¶
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 ¶
Effective resolves case-level overrides against suite and built-in defaults.
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.