Prepare resolved documents and autocorrection rules
This commit is contained in:
@@ -69,13 +69,9 @@ func RenderSessionDocument(cfg *Config, sessionID string) ([]byte, error) {
|
||||
if result != nil {
|
||||
metadata = result.Metadata()
|
||||
}
|
||||
// Materialized sessions retain authored overrides and receiving-campaign defaults.
|
||||
inputValue := func(name, value string) *string {
|
||||
if result != nil {
|
||||
if !metadata.IsExplicit(configkit.Keys("inputs", name)) {
|
||||
return nil
|
||||
}
|
||||
} else if value == "" {
|
||||
// Materialized sessions carry the resolved values needed independently of the campaign.
|
||||
inputValue := func(value string) *string {
|
||||
if value == "" {
|
||||
return nil
|
||||
}
|
||||
return &value
|
||||
@@ -87,8 +83,8 @@ func RenderSessionDocument(cfg *Config, sessionID string) ([]byte, error) {
|
||||
SpeakersFile *string `yaml:"speakers_file,omitempty"`
|
||||
Extra map[string]any `yaml:",inline"`
|
||||
}{doc.Inputs.AudioDir, doc.Inputs.AudioFiles, doc.Inputs.AudioS3,
|
||||
inputValue("speakers_file", doc.Inputs.SpeakersFile),
|
||||
glossaryFields(result != nil, metadata, doc.Inputs.Setting, doc.Inputs.System, doc.Inputs.GlossaryFile, doc.Inputs.Glossary, true)}
|
||||
inputValue(doc.Inputs.SpeakersFile),
|
||||
glossaryFields(result != nil, metadata, doc.Inputs.Setting, doc.Inputs.System, doc.Inputs.GlossaryFile, doc.Inputs.Glossary, false)}
|
||||
autocorrectPath := configkit.Keys("inputs", "autocorrect")
|
||||
if result != nil && metadata.IsExplicit(autocorrectPath) {
|
||||
if info, ok := metadata.Lookup(autocorrectPath); ok && info.Null {
|
||||
@@ -96,7 +92,7 @@ func RenderSessionDocument(cfg *Config, sessionID string) ([]byte, error) {
|
||||
} else {
|
||||
inputs.Extra["autocorrect"] = doc.Inputs.Autocorrect
|
||||
}
|
||||
} else if result == nil && doc.Inputs.Autocorrect != nil {
|
||||
} else if doc.Inputs.Autocorrect != nil {
|
||||
inputs.Extra["autocorrect"] = doc.Inputs.Autocorrect
|
||||
}
|
||||
value := struct {
|
||||
@@ -110,6 +106,16 @@ func RenderSessionDocument(cfg *Config, sessionID string) ([]byte, error) {
|
||||
return yaml.Marshal(value)
|
||||
}
|
||||
|
||||
// RenderAutocorrection produces the Seriatim rule-list envelope.
|
||||
func RenderAutocorrection(rules []AutocorrectionRule) ([]byte, error) {
|
||||
if rules == nil {
|
||||
rules = []AutocorrectionRule{}
|
||||
}
|
||||
return yaml.Marshal(struct {
|
||||
Autocorrect []AutocorrectionRule `yaml:"autocorrect"`
|
||||
}{Autocorrect: rules})
|
||||
}
|
||||
|
||||
func glossaryFields(hasResult bool, metadata configkit.Metadata, setting, system, file *string, glossary map[string]any, authoredOnly bool) map[string]any {
|
||||
result := map[string]any{}
|
||||
for _, field := range []struct {
|
||||
|
||||
Reference in New Issue
Block a user