Avoid repeated glossary selection and membership work
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
package config
|
||||
|
||||
import ck "go.maximumdirect.net/configkit"
|
||||
import (
|
||||
"slices"
|
||||
|
||||
ck "go.maximumdirect.net/configkit"
|
||||
)
|
||||
|
||||
func cloneSelection(value *string) *string {
|
||||
if value == nil {
|
||||
@@ -10,26 +14,25 @@ func cloneSelection(value *string) *string {
|
||||
return &copied
|
||||
}
|
||||
|
||||
func cloneNames(value []string) []string {
|
||||
if value == nil {
|
||||
return nil
|
||||
func defaultNames(r *ck.Resolution, path ck.Path, target *[]string, inherited []string, reason string, source ck.Path) {
|
||||
if !r.IsExplicit(path) {
|
||||
ck.Default(r, path, target, slices.Clone(inherited), reason, source)
|
||||
}
|
||||
return append([]string{}, value...)
|
||||
}
|
||||
|
||||
// resolveSettings records root-derived defaults after all explicit assignments.
|
||||
func resolveSettings(c *Config, r *ck.Resolution) error {
|
||||
glossaries := ck.Keys("glossaries")
|
||||
protection := ck.Keys("protected_terms")
|
||||
ck.Default(r, protection, &c.ProtectedTerms, cloneNames(c.Glossaries), "protection defaults to selected glossaries", glossaries)
|
||||
defaultNames(r, protection, &c.ProtectedTerms, c.Glossaries, "protection defaults to selected glossaries", glossaries)
|
||||
rootValidation := ck.Keys("llm", "validation_profile")
|
||||
rootValidationInfo, _ := r.EntryInfo(rootValidation)
|
||||
inheritedValidation := r.IsExplicit(rootValidation) && !rootValidationInfo.Null && c.LLM.ValidationProfile != nil
|
||||
for i := range c.Pipeline.Stages {
|
||||
item := &c.Pipeline.Stages[i]
|
||||
base := ck.Keys("pipeline", "stages").Index(i)
|
||||
ck.Default(r, base.Key("glossaries"), &item.Glossaries, cloneNames(c.Glossaries), "inherit root glossaries", glossaries)
|
||||
ck.Default(r, base.Key("protected_terms"), &item.ProtectedTerms, cloneNames(c.ProtectedTerms), "inherit root protection", protection)
|
||||
defaultNames(r, base.Key("glossaries"), &item.Glossaries, c.Glossaries, "inherit root glossaries", glossaries)
|
||||
defaultNames(r, base.Key("protected_terms"), &item.ProtectedTerms, c.ProtectedTerms, "inherit root protection", protection)
|
||||
threshold := ck.Keys("thresholds", item.Module)
|
||||
var value float64
|
||||
switch item.Module {
|
||||
|
||||
Reference in New Issue
Block a user