156 lines
5.0 KiB
Go
156 lines
5.0 KiB
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
type CLIOverrides struct {
|
|
ModulesCSV *string
|
|
PrimaryLLMAPIKey *string
|
|
ValidationLLMAPIKey *string
|
|
PrimaryModel *string
|
|
ValidationModel *string
|
|
PrimaryBaseURL *string
|
|
ValidationBaseURL *string
|
|
PrimaryLLMTimeoutSeconds *int
|
|
TotalLLMConcurrency *int
|
|
ProposalLLMConcurrency *int
|
|
PrimaryLLMConcurrency *int
|
|
ValidationLLMTimeoutSeconds *int
|
|
MaxRetries *int
|
|
ValidationMaxRetries *int
|
|
ValidationLLMConcurrency *int
|
|
ValidationMaxPromptTokens *int
|
|
MaxSectionTokens *int
|
|
MinSectionTokens *int
|
|
TargetSections *int
|
|
GlossaryConfidenceThreshold *float64
|
|
GrammarConfidenceThreshold *float64
|
|
HomophonesConfidenceThreshold *float64
|
|
SpokenWordConfidenceThreshold *float64
|
|
NormalizeMaxSegmentGap *float64
|
|
NormalizeEllipsisGap *float64
|
|
NormalizeMaxSegmentDuration *float64
|
|
NormalizeMaxSegmentTokens *int
|
|
TranscriptDescription *string
|
|
WorkDir *string
|
|
WorkDirRetention *string
|
|
}
|
|
|
|
func (c *Config) ApplyCLIOverrides(overrides CLIOverrides) error {
|
|
if overrides.ModulesCSV != nil {
|
|
modules, err := ParseModulesCSV(*overrides.ModulesCSV)
|
|
if err != nil {
|
|
return fmt.Errorf("--modules: %w", err)
|
|
}
|
|
c.Modules = modules
|
|
}
|
|
|
|
if overrides.PrimaryLLMAPIKey != nil {
|
|
c.PrimaryLLM.APIKey = *overrides.PrimaryLLMAPIKey
|
|
}
|
|
if overrides.ValidationLLMAPIKey != nil {
|
|
c.ValidationLLM.APIKey = *overrides.ValidationLLMAPIKey
|
|
}
|
|
if overrides.PrimaryModel != nil {
|
|
c.PrimaryLLM.Model = *overrides.PrimaryModel
|
|
}
|
|
if overrides.ValidationModel != nil {
|
|
c.ValidationLLM.Model = *overrides.ValidationModel
|
|
}
|
|
if overrides.PrimaryBaseURL != nil {
|
|
c.PrimaryLLM.BaseURL = *overrides.PrimaryBaseURL
|
|
}
|
|
if overrides.ValidationBaseURL != nil {
|
|
c.ValidationLLM.BaseURL = *overrides.ValidationBaseURL
|
|
}
|
|
if overrides.PrimaryLLMTimeoutSeconds != nil {
|
|
c.PrimaryLLM.TimeoutSeconds = *overrides.PrimaryLLMTimeoutSeconds
|
|
}
|
|
totalConcurrencySet := false
|
|
if overrides.TotalLLMConcurrency != nil {
|
|
c.TotalLLMConcurrency = *overrides.TotalLLMConcurrency
|
|
totalConcurrencySet = true
|
|
}
|
|
// Backward-compatible alias: --llm-concurrency maps to total concurrency
|
|
// only when --total-llm-concurrency is not set in the same CLI invocation.
|
|
if overrides.PrimaryLLMConcurrency != nil && !totalConcurrencySet {
|
|
c.TotalLLMConcurrency = *overrides.PrimaryLLMConcurrency
|
|
totalConcurrencySet = true
|
|
}
|
|
proposalConcurrencySet := false
|
|
if overrides.ProposalLLMConcurrency != nil {
|
|
c.ProposalLLMConcurrency = *overrides.ProposalLLMConcurrency
|
|
proposalConcurrencySet = true
|
|
}
|
|
if totalConcurrencySet && !proposalConcurrencySet {
|
|
c.ProposalLLMConcurrency = c.TotalLLMConcurrency
|
|
}
|
|
if overrides.ValidationLLMTimeoutSeconds != nil {
|
|
value := *overrides.ValidationLLMTimeoutSeconds
|
|
c.ValidationLLM.TimeoutSeconds = &value
|
|
}
|
|
if overrides.MaxRetries != nil {
|
|
c.PrimaryLLM.MaxRetries = *overrides.MaxRetries
|
|
}
|
|
if overrides.ValidationMaxRetries != nil {
|
|
value := *overrides.ValidationMaxRetries
|
|
c.ValidationLLM.MaxRetries = &value
|
|
}
|
|
if overrides.ValidationLLMConcurrency != nil {
|
|
value := *overrides.ValidationLLMConcurrency
|
|
c.ValidationLLMConcurrency = &value
|
|
}
|
|
if overrides.ValidationMaxPromptTokens != nil {
|
|
c.ValidationMaxPromptTokens = *overrides.ValidationMaxPromptTokens
|
|
}
|
|
if overrides.MaxSectionTokens != nil {
|
|
c.MaxSectionTokens = *overrides.MaxSectionTokens
|
|
}
|
|
if overrides.MinSectionTokens != nil {
|
|
c.MinSectionTokens = *overrides.MinSectionTokens
|
|
}
|
|
if overrides.TargetSections != nil {
|
|
value := *overrides.TargetSections
|
|
c.TargetSections = &value
|
|
}
|
|
if overrides.GlossaryConfidenceThreshold != nil {
|
|
c.Thresholds.Glossary = *overrides.GlossaryConfidenceThreshold
|
|
}
|
|
if overrides.GrammarConfidenceThreshold != nil {
|
|
c.Thresholds.Grammar = *overrides.GrammarConfidenceThreshold
|
|
}
|
|
if overrides.HomophonesConfidenceThreshold != nil {
|
|
c.Thresholds.Homophones = *overrides.HomophonesConfidenceThreshold
|
|
}
|
|
if overrides.SpokenWordConfidenceThreshold != nil {
|
|
c.Thresholds.SpokenWord = *overrides.SpokenWordConfidenceThreshold
|
|
}
|
|
if overrides.NormalizeMaxSegmentGap != nil {
|
|
c.Normalization.MaxSegmentGap = *overrides.NormalizeMaxSegmentGap
|
|
}
|
|
if overrides.NormalizeEllipsisGap != nil {
|
|
c.Normalization.EllipsisGap = *overrides.NormalizeEllipsisGap
|
|
}
|
|
if overrides.NormalizeMaxSegmentDuration != nil {
|
|
c.Normalization.MaxSegmentDuration = *overrides.NormalizeMaxSegmentDuration
|
|
}
|
|
if overrides.NormalizeMaxSegmentTokens != nil {
|
|
c.Normalization.MaxSegmentTokens = *overrides.NormalizeMaxSegmentTokens
|
|
}
|
|
if overrides.TranscriptDescription != nil {
|
|
c.TranscriptDescription = strings.TrimSpace(*overrides.TranscriptDescription)
|
|
}
|
|
if overrides.WorkDir != nil {
|
|
c.WorkDir = *overrides.WorkDir
|
|
}
|
|
if overrides.WorkDirRetention != nil {
|
|
c.WorkDirRetention = WorkDirRetention(*overrides.WorkDirRetention)
|
|
}
|
|
|
|
c.syncLegacyConcurrencyAliases()
|
|
|
|
return c.Validate()
|
|
}
|