Configure correction repair profiles and budgets
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
ck "go.maximumdirect.net/configkit"
|
||||
@@ -158,3 +160,52 @@ pipeline:
|
||||
t.Fatalf("explicit null lost: %+v", info)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCorrectionRepairSettingsResolution(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name, root, local, want string
|
||||
budget int
|
||||
}{
|
||||
{"default", "", "proposal_profile: B", "B", 1},
|
||||
{"inherit explicit", "correction_repair_profile: R\n correction_repair_attempts: 5", "proposal_profile: B", "R", 5},
|
||||
{"clear root selection and budget", "correction_repair_profile: R\n correction_repair_attempts: 5", "proposal_profile: B\n correction_repair_profile: null\n correction_repair_attempts: 0", "B", 0},
|
||||
{"root null", "correction_repair_profile: null", "proposal_profile: B", "B", 1},
|
||||
{"explicit selection", "correction_repair_profile: R", "correction_repair_profile: S", "S", 1},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
doc := "llm:\n proposal_profile: A\n"
|
||||
if tc.root != "" {
|
||||
doc += " " + tc.root + "\n"
|
||||
}
|
||||
doc += "pipeline:\n stages:\n - module: grammar\n llm:\n " + tc.local + "\n"
|
||||
result, err := loadResolution(t, doc)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cfg := result.Config
|
||||
got := cfg.Pipeline.Stages[0].LLM
|
||||
if got.CorrectionRepairProfile == nil || *got.CorrectionRepairProfile != tc.want || got.CorrectionRepairAttempts != tc.budget {
|
||||
t.Fatalf("settings = %+v", got)
|
||||
}
|
||||
var effective bytes.Buffer
|
||||
if err := result.WriteEffective(&effective); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.Contains(effective.String(), "correction_repair_attempts:") || !strings.Contains(effective.String(), "correction_repair_profile:") {
|
||||
t.Fatalf("effective configuration: %s", effective.String())
|
||||
}
|
||||
if got.CorrectionRepairProfile == cfg.LLM.CorrectionRepairProfile || got.CorrectionRepairProfile == got.ProposalProfile {
|
||||
t.Fatal("profiles share storage")
|
||||
}
|
||||
path := ck.Keys("pipeline", "stages").Index(0).Key("llm").Key("correction_repair_profile")
|
||||
if _, ok := result.Explain(path); !ok {
|
||||
t.Fatal("missing resolution evidence")
|
||||
}
|
||||
})
|
||||
}
|
||||
for _, doc := range []string{"llm: {correction_repair_attempts: -1}", "pipeline:\n stages:\n - module: grammar\n llm: {correction_repair_attempts: -1}", "llm: {correction_repair_profile: ''}"} {
|
||||
if _, err := loadResolution(t, doc); err == nil {
|
||||
t.Errorf("accepted %s", doc)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user