95 lines
2.3 KiB
Go
95 lines
2.3 KiB
Go
package metadata
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"gitea.maximumdirect.net/eric/audita/internal/framework/contracts"
|
|
)
|
|
|
|
type ExecutionClass string
|
|
|
|
const (
|
|
ExecutionClassDeterministic ExecutionClass = "deterministic"
|
|
ExecutionClassLLMBacked ExecutionClass = "llm_backed"
|
|
)
|
|
|
|
const (
|
|
KeyProposalShape = "proposal_shape"
|
|
KeyConfidenceThreshold = "confidence_threshold"
|
|
KeyOriginalTextPresence = "original_text_presence"
|
|
KeyNonEmptyCorrectedText = "non_empty_corrected_text"
|
|
KeyNoEffect = "no_effect"
|
|
KeyProtectedTerms = "protected_terms"
|
|
|
|
KeySpokenFormPlausibility = "spoken_form_plausibility"
|
|
KeyMeaningReversalReview = "meaning_reversal_review"
|
|
KeyEditorialReview = "editorial_review"
|
|
)
|
|
|
|
var executionClassByKey = map[string]ExecutionClass{
|
|
KeyProposalShape: ExecutionClassDeterministic,
|
|
KeyConfidenceThreshold: ExecutionClassDeterministic,
|
|
KeyOriginalTextPresence: ExecutionClassDeterministic,
|
|
KeyNonEmptyCorrectedText: ExecutionClassDeterministic,
|
|
KeyNoEffect: ExecutionClassDeterministic,
|
|
KeyProtectedTerms: ExecutionClassDeterministic,
|
|
KeySpokenFormPlausibility: ExecutionClassLLMBacked,
|
|
KeyMeaningReversalReview: ExecutionClassLLMBacked,
|
|
KeyEditorialReview: ExecutionClassLLMBacked,
|
|
}
|
|
|
|
type ClassifiedValidator interface {
|
|
contracts.Validator
|
|
ExecutionClass() ExecutionClass
|
|
}
|
|
|
|
func ClassOf(v contracts.Validator) ExecutionClass {
|
|
if v == nil {
|
|
return ExecutionClassDeterministic
|
|
}
|
|
|
|
classFromKey := ClassForKey(v.Name())
|
|
classified, ok := v.(ClassifiedValidator)
|
|
if !ok {
|
|
return classFromKey
|
|
}
|
|
switch classified.ExecutionClass() {
|
|
case ExecutionClassLLMBacked:
|
|
return ExecutionClassLLMBacked
|
|
case ExecutionClassDeterministic:
|
|
return ExecutionClassDeterministic
|
|
default:
|
|
return classFromKey
|
|
}
|
|
}
|
|
|
|
func ClassForKey(key string) ExecutionClass {
|
|
class, ok := executionClassByKey[strings.TrimSpace(key)]
|
|
if !ok {
|
|
return ExecutionClassDeterministic
|
|
}
|
|
return class
|
|
}
|
|
|
|
func Wrap(v contracts.Validator, class ExecutionClass) contracts.Validator {
|
|
if v == nil {
|
|
return nil
|
|
}
|
|
if class != ExecutionClassLLMBacked {
|
|
class = ExecutionClassDeterministic
|
|
}
|
|
return wrappedValidator{
|
|
Validator: v,
|
|
class: class,
|
|
}
|
|
}
|
|
|
|
type wrappedValidator struct {
|
|
contracts.Validator
|
|
class ExecutionClass
|
|
}
|
|
|
|
func (w wrappedValidator) ExecutionClass() ExecutionClass {
|
|
return w.class
|
|
}
|