Skip to content

armgit / laya

Public Imported from GitHub
0

Non-autoregressive System 1 decision engine. Typed choice, score and yes/no decisions over any text in a single forward pass, in 100+ languages, with a router that picks the right checkpoint per request.

laya-go: PredictLong refuses the confidence gate

Adeshina Lasisi27ef6ea21f18
diff --git a/laya-go/agent/gate_test.go b/laya-go/agent/gate_test.go
index 903898c9..1987cb92 100644
--- a/laya-go/agent/gate_test.go
+++ b/laya-go/agent/gate_test.go
@@ -105,9 +105,8 @@ func TestInvalidThresholdFailsBeforeAnyWork(t *testing.T) {
func TestPredictLongWritesNoGateField(t *testing.T) {
a, _ := open(t, `{}`)
- // PredictLong has no gate: laya calls it with None, which writes nothing, so even a given
- // option leaves the answers as ungated.
- lp, err := a.PredictLong(context.Background(), "hello", questions(t), agent.WithMinConfidence(1))
+ // PredictLong has no gate: laya calls it with None, which writes nothing.
+ lp, err := a.PredictLong(context.Background(), "hello", questions(t))
if err != nil {
t.Fatal(err)
}
@@ -118,7 +117,7 @@ func TestPredictLongWritesNoGateField(t *testing.T) {
func TestPredictLongScanWritesNoGateField(t *testing.T) {
a, _ := open(t, longConfig)
- lp, err := a.PredictLong(context.Background(), longState(900), questions(t), agent.WithMinConfidence(1))
+ lp, err := a.PredictLong(context.Background(), longState(900), questions(t))
if err != nil {
t.Fatal(err)
}
@@ -129,3 +128,23 @@ func TestPredictLongScanWritesNoGateField(t *testing.T) {
t.Fatalf("a scanned PredictLong carries a gate field: %s", s)
}
}
+
+func TestPredictLongRefusesTheGate(t *testing.T) {
+ // Python's predict_long raises TypeError for min_confidence; ignoring it would hand back
+ // ungated answers to a caller who asked for a gate.
+ for name, opt := range map[string]agent.CallOption{
+ "threshold": agent.WithMinConfidence(0.5),
+ "map": agent.WithMinConfidenceMap(map[string]float64{"default": 0.5}),
+ } {
+ for _, state := range []any{"hello", longState(900)} {
+ a, s := open(t, longConfig)
+ _, err := a.PredictLong(context.Background(), state, questions(t), opt)
+ if err == nil || !strings.Contains(err.Error(), "PredictLong takes no confidence gate") {
+ t.Fatalf("%s: want the gate refused, got %v", name, err)
+ }
+ if len(s.seen()) != 0 {
+ t.Fatalf("%s: the session ran", name)
+ }
+ }
+ }
+}
diff --git a/laya-go/agent/long.go b/laya-go/agent/long.go
index 78556cc4..011d7653 100644
--- a/laya-go/agent/long.go
+++ b/laya-go/agent/long.go
@@ -2,6 +2,7 @@ package agent
import (
"context"
+ "errors"
"fmt"
"slices"
@@ -47,8 +48,9 @@ type LongPrediction struct {
// WithWindow, WithStride, WithBatchSize (windows per run; by default the scan bounds a run as
// laya's window_batch_cap does) and WithLanguage apply. A *StateError names a window, not the
// state. Errors are those of PredictBatch, and sequence.ErrNoRoom and sequence.ErrStrideGap when
-// the questions leave no room or the stride leaves gaps. The confidence gate and hooks are not
-// applied, and Go has no calibration.
+// the questions leave no room or the stride leaves gaps. WithMinConfidence and
+// WithMinConfidenceMap are refused with an error before any work, as Python raises TypeError for
+// min_confidence; hooks are not applied, and Go has no calibration.
func (a *Agent) PredictLong(ctx context.Context, state any, qs schema.Questions, opts ...CallOption) (LongPrediction, error) {
var c call
for _, opt := range opts {
@@ -56,6 +58,11 @@ func (a *Agent) PredictLong(ctx context.Context, state any, qs schema.Questions,
opt(&c)
}
}
+ if c.gated {
+ // Python's predict_long has no min_confidence argument (TypeError); ignoring the option
+ // would return ungated answers to a caller who asked for a gate.
+ return LongPrediction{}, errors.New("agent: PredictLong takes no confidence gate; use Predict or PredictBatch with WithMinConfidence")
+ }
if err := ctx.Err(); err != nil {
return LongPrediction{}, err
}