Documentation
¶
Overview ¶
Package target sends one benchmark question to a DocsGPT agent through one of four protocols: the OpenAI-compatible /v1/chat/completions endpoint (single JSON response or SSE), the native /stream SSE endpoint, the native /api/answer JSON endpoint, or an agent incoming webhook (async, with /api/task_status polling).
Index ¶
- Constants
- Variables
- func UploadAttachments(ctx context.Context, baseURL, apiKey string, paths []string, ...) ([]string, error)
- func UploadAttachmentsWithToken(ctx context.Context, baseURL, token string, paths []string, ...) ([]string, error)
- type Exchange
- type InlineFile
- type Request
- type Result
- type ServerError
- type Target
- type ToolCallInfo
- type Usage
Constants ¶
const BenchTagHeader = "X-DocsGPT-Bench-Tag"
BenchTagHeader carries the run tag (--run-tag / bench.yaml run_tag) as "bench:<tag>" so telemetry can attribute (and exclude) bench traffic.
Variables ¶
var UserAgent = "docsgpt-cli-bench"
UserAgent is sent with every bench request so server-side telemetry can tell bench traffic from real users. The CLI stamps its version at startup.
Functions ¶
func UploadAttachments ¶
func UploadAttachments(ctx context.Context, baseURL, apiKey string, paths []string, pollInterval time.Duration) ([]string, error)
UploadAttachments uploads each file to POST {baseURL}/api/store_attachment (multipart, with the agent api_key as a form field) and returns the resulting server-side attachment ids in the same order as paths. When an upload returns a task instead of a direct id, it polls /api/task_status until the id is ready. One file is sent per request for simplicity.
func UploadAttachmentsWithToken ¶
func UploadAttachmentsWithToken(ctx context.Context, baseURL, token string, paths []string, pollInterval time.Duration) ([]string, error)
UploadAttachmentsWithToken is UploadAttachments for runs that address the agent by id: there is no agent api_key, so the upload is authenticated with the personal access token as the Bearer credential and the attachment is owned by the token's user.
Types ¶
type Exchange ¶
Exchange is one completed user/assistant pair of an earlier turn, replayed by stateless targets (v1) to continue a conversation.
type InlineFile ¶
type InlineFile struct {
Name string // filename shown to the model
Path string // local file path, read at request time
}
InlineFile is an attachment sent inline as a base64 content part (v1 only).
type Request ¶
type Request struct {
Question string
AttachmentIDs []string // server-side attachment ids (see UploadAttachments)
InlineFiles []InlineFile // v1 inline attachments (attachments_mode: inline)
Model string // model id (stream/answer: model_id, v1: model); "" = agent default
Stream bool // v1: request SSE streaming instead of a single JSON response
// Multi-turn support. ConversationID continues an existing conversation
// (stream/answer targets); History is replayed as prior messages by
// stateless targets (v1). The runner fills whichever the target uses.
ConversationID string
History []Exchange
BaseURL string
APIKey string // agent API key (v1: Bearer; stream/answer: api_key in the body)
// AgentID + Token select an agent by id instead of by API key
// (stream/answer only): the body carries agent_id and the request is
// authenticated with `Authorization: Bearer <personal access token>`
// (scope chat:run). Exactly one of APIKey / AgentID is set.
AgentID string
Token string
WebhookURL string // webhook target only
Timeout time.Duration // whole-run budget, including webhook polling
PollInterval time.Duration // webhook polling cadence
RunTag string // sent as X-DocsGPT-Bench-Tag: bench:<tag>
}
Request carries everything a target needs for one run.
type Result ¶
type Result struct {
Answer string `json:"answer"`
Thought string `json:"thought,omitempty"`
Sources []map[string]any `json:"sources,omitempty"`
ToolCalls []ToolCallInfo `json:"tool_calls,omitempty"`
ConversationID string `json:"conversation_id,omitempty"`
Usage *Usage `json:"usage,omitempty"` // nil unless the target reports it (v1 only)
Latency time.Duration `json:"latency_ns"`
// FirstOutput is the time from request start to the first answer content
// (stream: first `answer`/`structured_answer` frame; v1 streamed: first
// content delta). Zero when the protocol cannot observe it.
FirstOutput time.Duration `json:"first_output_ns,omitempty"`
// SSE integrity (stream target only; nil/false elsewhere).
Frames []string `json:"frames,omitempty"` // distinct frame types in order of first appearance
EndFrame bool `json:"end_frame,omitempty"`
ErrorFrame bool `json:"error_frame,omitempty"`
}
Result is the normalized outcome of one agent run, whatever the protocol.
type ServerError ¶
type ServerError struct {
Status int // HTTP status of the response (0 when not applicable)
Message string // extracted error message (error.message, error, or body)
Body string // raw (truncated) response body / frame, for diagnostics
Where string // endpoint or protocol label
}
ServerError is returned when the server answered but reported a failure: a non-2xx HTTP status, an SSE `error` frame, or an agent-level failure in a task result. Negative cases (expect.error) assert against it; anything else (transport failures, timeouts, malformed responses) stays a plain error and is reported as a run error.
func (*ServerError) Error ¶
func (e *ServerError) Error() string
type ToolCallInfo ¶
type ToolCallInfo struct {
Name string `json:"name"`
Arguments string `json:"arguments,omitempty"`
}
ToolCallInfo is one tool invocation reported by the server.