Retain selected glossary instructions

This commit is contained in:
2026-11-26 18:14:27 +00:00
parent d2c4c63580
commit b1cde637a2
5 changed files with 51 additions and 2 deletions

View File

@@ -31,6 +31,11 @@ type TranscriptModule interface {
type StructuredCompletionRequest = structuredoutput.Request
type StructuredCompletionResponse = structuredoutput.Response
type GlossaryInstruction struct {
Collection string
Text string
}
// ModuleRunSpec identifies one resolved module instance in a pipeline.
type ModuleRunSpec struct {
ModuleKey string `json:"module_key"`
@@ -40,6 +45,7 @@ type ModuleRunSpec struct {
ID *string `json:"-"`
Settings config.Stage `json:"-"`
Glossary []glossary.Entry `json:"-"`
GlossaryInstructions []GlossaryInstruction `json:"-"`
ProtectedTerms []glossary.Term `json:"-"`
GlossaryView *validators.GlossaryView `json:"-"`
GlossaryVariables *promptcontext.GlossaryVariables `json:"-"`
@@ -140,10 +146,16 @@ func ResolveModuleRunSpecs(cfg *config.Config) []ModuleRunSpec {
key := GlossarySelection(item)
if prior, ok := selections[key]; ok {
spec.Glossary = specs[prior].Glossary
spec.GlossaryInstructions = specs[prior].GlossaryInstructions
spec.ProtectedTerms = specs[prior].ProtectedTerms
continue
}
selected := glossary.Select(cfg.GlossaryCollections, item.Glossaries)
for _, name := range item.Glossaries {
if collection, ok := cfg.GlossaryCollections[name]; ok {
spec.GlossaryInstructions = append(spec.GlossaryInstructions, GlossaryInstruction{Collection: name, Text: collection.Instruction})
}
}
protected := glossary.Select(cfg.GlossaryCollections, item.ProtectedTerms)
var excluded []glossary.Entry
if key.exempt {

View File

@@ -92,6 +92,29 @@ func TestResolveModuleRunSpecs(t *testing.T) {
}
}
func TestResolveGlossaryInstructions(t *testing.T) {
cfg := &config.Config{
GlossaryCollections: map[string]config.GlossaryCollection{
"one": {Instruction: "First"}, "two": {Instruction: "Second"}, "protected": {Instruction: "Protection only"},
},
Pipeline: config.Pipeline{Stages: []config.Stage{
{Module: "grammar", Glossaries: []string{"two", "one"}, ProtectedTerms: []string{"protected"}},
{Module: "grammar", Glossaries: []string{"two", "one"}, ProtectedTerms: []string{"protected"}},
{Module: "grammar", Glossaries: []string{"one"}, ProtectedTerms: []string{"protected"}},
}},
}
specs := ResolveModuleRunSpecs(cfg)
want := []GlossaryInstruction{{Collection: "two", Text: "Second"}, {Collection: "one", Text: "First"}}
for _, spec := range specs[:2] {
if !reflect.DeepEqual(spec.GlossaryInstructions, want) {
t.Fatalf("instructions = %+v, want %+v", spec.GlossaryInstructions, want)
}
}
if !reflect.DeepEqual(specs[2].GlossaryInstructions, want[1:]) {
t.Fatalf("specific selection = %+v", specs[2].GlossaryInstructions)
}
}
func TestSectionMetadataFromSection(t *testing.T) {
section := chunking.Section{
Index: 3,