feat(guards): judge calls record their payload and response, and the OpenAI Decisions API is a judge backend
publish / publish (push) Successful in 1m18s
publish / publish (push) Successful in 1m18s
This commit is contained in:
27 files changed
+2230
-99
No files matched your search
@@ -21,6 +21,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/samcharles93/archipelago/guards/integrity/internal/audit"
|
||||
"github.com/samcharles93/archipelago/sdk/judgegate"
|
||||
"github.com/samcharles93/archipelago/sdk/systemone"
|
||||
)
|
||||
|
||||
@@ -112,11 +113,16 @@ type Verdict struct {
|
||||
LatencyMS int
|
||||
Truncated bool
|
||||
Error string
|
||||
// RequestJSON is the exact body sent to the classifier, and Questions the set
|
||||
// it was asked. Storing them makes the judgement reproducible and turns the
|
||||
// audit log into a training set that matches production.
|
||||
RequestJSON []byte
|
||||
Questions map[string]systemone.Question
|
||||
// RequestJSON is the exact body sent to the classifier, Response the exact
|
||||
// body it returned, and Questions the set it was asked. Storing them makes
|
||||
// the judgement reproducible and turns the audit log into a training set
|
||||
// that matches production. RequestJSON and Response are kept on a failed
|
||||
// call too.
|
||||
RequestJSON []byte
|
||||
Response []byte
|
||||
EndpointPath string
|
||||
HTTPStatus int
|
||||
Questions map[string]systemone.Question
|
||||
}
|
||||
|
||||
// Ok reports whether the judge produced usable answers.
|
||||
@@ -131,22 +137,29 @@ type Judge interface {
|
||||
Judge(ctx context.Context, b *audit.Bundle, rep *audit.Report, opts Options) Verdict
|
||||
}
|
||||
|
||||
// SystemOne judges with a System One decision model, locally through llama.cpp's
|
||||
// /v1/systemone or hosted through a provider that exposes classifiers.
|
||||
// SystemOne judges with a model behind a judge backend: System One locally
|
||||
// through llama.cpp's /v1/systemone or hosted, or the OpenAI Decisions API.
|
||||
type SystemOne struct {
|
||||
Client systemone.Client
|
||||
Client judgegate.Client
|
||||
// Kind names the backend in reports; empty means systemone.
|
||||
Kind string
|
||||
}
|
||||
|
||||
// Name identifies the implementation in reports.
|
||||
func (s SystemOne) Name() string { return "systemone" }
|
||||
func (s SystemOne) Name() string {
|
||||
if s.Kind != "" {
|
||||
return s.Kind
|
||||
}
|
||||
return judgegate.APISystemOne
|
||||
}
|
||||
|
||||
// Judge asks one question set about the call and its deterministic findings.
|
||||
func (s SystemOne) Judge(ctx context.Context, b *audit.Bundle, rep *audit.Report, opts Options) Verdict {
|
||||
opts = opts.withDefaults()
|
||||
v := Verdict{
|
||||
Provider: s.Client.Label,
|
||||
Deployment: s.Client.Label,
|
||||
Model: s.Client.Model,
|
||||
Provider: s.Client.Deployment(),
|
||||
Deployment: s.Client.Deployment(),
|
||||
Model: s.Client.ModelID(),
|
||||
Authority: opts.Authority,
|
||||
MinConfidence: opts.MinConfidence,
|
||||
Signals: map[string]float64{},
|
||||
@@ -155,13 +168,13 @@ func (s SystemOne) Judge(ctx context.Context, b *audit.Bundle, rep *audit.Report
|
||||
state, truncated := State(b, rep, opts)
|
||||
v.Truncated = truncated
|
||||
questions := Questions(b, rep, opts)
|
||||
|
||||
if body, err := s.Client.BuildRequest(state, systemone.QuestionWires(questions)); err == nil {
|
||||
v.RequestJSON = body
|
||||
v.Questions = questions
|
||||
}
|
||||
v.Questions = questions
|
||||
|
||||
res, err := s.Client.Classify(ctx, state, questions)
|
||||
v.RequestJSON = res.Request
|
||||
v.Response = res.Response
|
||||
v.EndpointPath = res.EndpointPath
|
||||
v.HTTPStatus = res.HTTPStatus
|
||||
v.LatencyMS = int(res.Latency.Milliseconds())
|
||||
v.Usage = res.Usage
|
||||
if err != nil {
|
||||
|
||||
Reference in new issue
Block a user