diff --git a/internal/cli/ctl_request.go b/internal/cli/ctl_request.go index b6af3b4..036b888 100644 --- a/internal/cli/ctl_request.go +++ b/internal/cli/ctl_request.go @@ -13,7 +13,7 @@ import ( func newRequestCmd(client func() *ctlClient, asJSON *bool) *cobra.Command { return &cobra.Command{ Use: "request ID", - Short: "What one request went through: replica, queue, first token, tokens", + Short: "What one request went through: replica, queue, first token, tokens, guardrails", Long: "Every response carries its id in X-Request-Id, and a client may send its\n" + "own. Given one, this says which replica answered, how long admission held\n" + "it, how long the first token took and what it cost — the answer to \"why\n" + @@ -39,6 +39,12 @@ func newRequestCmd(client func() *ctlClient, asJSON *bool) *cobra.Command { fmt.Fprintf(out, "time %d ms total: %d queued, %d to the first token\n", v.LatencyMs, v.QueueMs, v.TTFTMs) fmt.Fprintf(out, "tokens %d in, %d out\n", v.PromptTokens, v.CompletionTokens) fmt.Fprintf(out, "who key %s, project %s%s\n", v.KeyID, v.ProjectID, prefixed(", user ", v.UserID)) + if v.GuardAction != "" { + fmt.Fprintf(out, "guard %s by policy %s (%s), %d ms\n", v.GuardAction, v.GuardPolicy, + or(v.GuardCategory, "-"), v.GuardMs) + } else if v.GuardMs > 0 { + fmt.Fprintf(out, "guard allowed, %d ms\n", v.GuardMs) + } return nil }, } diff --git a/internal/control/adminapi/api.go b/internal/control/adminapi/api.go index c91b968..ee28abe 100644 --- a/internal/control/adminapi/api.go +++ b/internal/control/adminapi/api.go @@ -1393,6 +1393,11 @@ type RequestView struct { PromptTokens int64 `json:"prompt_tokens"` CompletionTokens int64 `json:"completion_tokens"` CostMicros int64 `json:"cost_micros"` + // What the guardrails did, by name. + GuardAction string `json:"guard_action,omitempty"` + GuardPolicy string `json:"guard_policy,omitempty"` + GuardCategory string `json:"guard_category,omitempty"` + GuardMs int64 `json:"guard_ms,omitempty"` } func (a *API) request(w http.ResponseWriter, r *http.Request) { @@ -1415,6 +1420,7 @@ func (a *API) request(w http.ResponseWriter, r *http.Request) { Model: u.Model, ServedModel: u.ServedModel, Replica: u.Replica, Status: u.Status, LatencyMs: u.LatencyMs, QueueMs: u.QueueMs, TTFTMs: u.TTFTMs, PromptTokens: u.PromptTokens, CompletionTokens: u.CompletionTokens, CostMicros: u.CostMicros, + GuardAction: u.GuardAction, GuardPolicy: u.GuardPolicy, GuardCategory: u.GuardCategory, GuardMs: u.GuardMs, }) } diff --git a/internal/web/templates/chat.html b/internal/web/templates/chat.html index 1a00111..b927f8a 100644 --- a/internal/web/templates/chat.html +++ b/internal/web/templates/chat.html @@ -75,6 +75,11 @@ access to it.