Files
audita/internal/framework/promptcontext/glossary.go

33 lines
964 B
Go

package promptcontext
import (
"encoding/json"
"fmt"
"gitea.maximumdirect.net/eric/audita/v3/internal/core/glossary"
)
// GlossaryVariables contains the glossary inputs shared by a stage's proposals.
type GlossaryVariables struct {
ContextJSON string
ProtectionJSON string
}
func PrepareGlossaryVariables(entries []glossary.Entry, terms []glossary.Term) (GlossaryVariables, error) {
contextJSON, err := json.MarshalIndent(entries, "", " ")
if err != nil {
return GlossaryVariables{}, fmt.Errorf("marshal glossary prompt context: %w", err)
}
protected := make([]string, 0, len(terms))
for _, term := range terms {
if !term.Exempt {
protected = append(protected, term.Spelling)
}
}
protectionJSON, err := json.Marshal(protected)
if err != nil {
return GlossaryVariables{}, fmt.Errorf("marshal protected spellings: %w", err)
}
return GlossaryVariables{ContextJSON: string(contextJSON), ProtectionJSON: string(protectionJSON)}, nil
}