Documentation
¶
Overview ¶
Package inference implements the active-inference eval.Target: it drives a scenario's input thread through an inference.Client and projects the model's reply into an eval.Observation. It is one of the two eval packages (with judge/) permitted to depend on github.com/looprig/inference; the eval root package never imports it.
Package-name / import-collision note: the directory is target/inference/, so the idiomatic package name (matching the directory) is "inference" — which collides with the module github.com/looprig/inference this package must import. The collision is resolved by aliasing the MODULE import as llm within this package. The public import path stays github.com/looprig/eval/target/ inference; a caller that also imports the real inference module simply aliases one of them (the design's inferenceeval.NewTarget is such a caller alias).
The target is fail-secure. It clones the request template before use so a concurrent Observe never mutates the caller's template or races on a shared backing array; it appends the read-only scenario input without writing back into the scenario; and every path that cannot produce a validated Observation returns a typed, content-free error rather than a partial observation. Secrets (API keys, auth headers, the template System prompt, raw provider error text) never reach the trace, subject, operation attributes, or evidence — only safe model identity, token counts, and timings do.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewTarget ¶
NewTarget returns an inference eval.Target. The template supplies the Model and any System, Tools, or sampling defaults; Observe fills the request's Messages with the template messages followed by the scenario input on each call. By default the target's Name, subject Name, and subject/trace Revision are derived from the template model's wire id; options override each.
NewTarget does not reject a misconfigured template: an invalid derived identity surfaces as a typed IdentityError from Observe (before any model is called), so a construction-time mistake is reported by the first Observe rather than panicking at construction. The client must be non-nil.
Types ¶
type EmptyResponseError ¶
type EmptyResponseError struct {
Reason EmptyResponseReason
}
EmptyResponseError reports that Invoke returned success but no usable result: a nil *Response, or a response without an assistant message. The target fails secure — it never fabricates an empty observation from a missing result. Reason is a closed-enum classification, always safe to render.
func (*EmptyResponseError) Error ¶
func (e *EmptyResponseError) Error() string
type EmptyResponseReason ¶
type EmptyResponseReason string
EmptyResponseReason classifies a structurally empty inference response. There is no valid zero value: an unclassified empty response is never constructed.
const ( // ReasonNilResponse: Invoke returned a nil *Response with no error. ReasonNilResponse EmptyResponseReason = "nil_response" // ReasonNilMessage: the response carried no assistant message. ReasonNilMessage EmptyResponseReason = "nil_message" )
type IdentityError ¶
type IdentityError struct {
Cause error
}
IdentityError reports that the target's configured model identity (its derived Name, Revision, or subject ID) is not well-formed, so no valid Observation could be produced. It is a configuration failure detected before any model is called. Cause is the underlying eval validation error — drawn from eval's safe vocabulary and carrying no untrusted content — available via Unwrap.
func (*IdentityError) Error ¶
func (e *IdentityError) Error() string
func (*IdentityError) Unwrap ¶
func (e *IdentityError) Unwrap() error
type InferenceError ¶
type InferenceError struct {
Cause error
}
InferenceError reports that the inference call itself failed: an unreachable provider, a transport error, a cancelled context, or an exceeded deadline. The underlying error is available via Unwrap — so callers can test for context.Canceled or context.DeadlineExceeded with errors.Is — but is never rendered, since it may originate outside the process and carry untrusted text.
func (*InferenceError) Error ¶
func (e *InferenceError) Error() string
func (*InferenceError) Unwrap ¶
func (e *InferenceError) Unwrap() error
type ObservationInvalidError ¶
type ObservationInvalidError struct {
Cause error
}
ObservationInvalidError reports that the target assembled an observation that failed eval.Observation.Validate. It is a defensive guard: the projection is built to be valid, so this signals an internal inconsistency rather than a caller error. Cause is the eval validation error (safe vocabulary), available via Unwrap.
func (*ObservationInvalidError) Error ¶
func (e *ObservationInvalidError) Error() string
func (*ObservationInvalidError) Unwrap ¶
func (e *ObservationInvalidError) Unwrap() error
type Option ¶
type Option func(*options)
Option configures a target built by NewTarget.
func WithClock ¶
WithClock injects the clock used to timestamp the inference operation. It defaults to time.Now; tests pin it to assert exact timing.
func WithName ¶
WithName overrides the target's stable name (used for Name() and the observation subject). It defaults to the template model's wire id.
func WithRevision ¶
WithRevision overrides the model revision recorded on the subject and trace. It defaults to the template model's wire id. A caller aligning the observation with a scenario's qualified revision sets this so Sample.Validate accepts it.
func WithSubjectID ¶
WithSubjectID sets the subject's correlation identifier. It defaults to the target name, which is a stable, deterministic value.