96 lines
7.1 KiB
Go
96 lines
7.1 KiB
Go
package validators
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"gitea.maximumdirect.net/eric/audita/internal/framework/promptcontext"
|
|
)
|
|
|
|
func BuildSpokenFormPlausibilityMessages(validationPayload []LLMValidationItem, transcriptDescription string) ([]LLMMessage, error) {
|
|
payloadJSON, err := marshalPromptPayload(validationPayload)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
system := "You are Audita, a conservative spoken-form validation assistant. Evaluate whether each proposed correction is plausibly explained by a homophone, phonetic similarity, or a common mistranscription of spoken English. Your job is not to improve style or readability. Approve only when the corrected text is a plausible recovery of the words that were likely spoken."
|
|
user := "Review these proposed transcript corrections and decide whether each one is a plausible spoken-form correction.\n\n" +
|
|
"Rules:\n" +
|
|
"- Return one validation decision for every correction_index in the input.\n" +
|
|
"- Approve when the original text and corrected text are plausibly related by homophone confusion, phonetic similarity, or a common spoken-word mistranscription, and the surrounding segment context supports the correction.\n" +
|
|
"- Examples that may be approved when context supports them: changing \"gestures\" to \"Jesters\", \"rank\" to \"Hrank\", or \"dam\" to \"damn\".\n" +
|
|
"- Reject unrelated substitutions like changing \"Lyra\" to \"Jesters\".\n" +
|
|
"- Judge spoken-form plausibility, not whether the correction is cleaner, more formal, or more grammatical.\n" +
|
|
"- Do not approve paraphrases, stylistic rewrites, or arbitrary semantic substitutions.\n" +
|
|
"- If a correction includes categories, treat them as additional segment context.\n" +
|
|
"- Each returned validation must contain only correction_index, approved, confidence, and reason.\n" +
|
|
"- confidence must be between 0.0 and 1.0.\n\n" +
|
|
promptcontext.TranscriptDescriptionBlock(transcriptDescription) +
|
|
fmt.Sprintf("Corrections to validate:\n%s", payloadJSON)
|
|
return []LLMMessage{{Role: "system", Content: system}, {Role: "user", Content: user}}, nil
|
|
}
|
|
|
|
func BuildMeaningReversalMessages(validationPayload []LLMValidationItem, transcriptDescription string) ([]LLMMessage, error) {
|
|
payloadJSON, err := marshalPromptPayload(validationPayload)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
system := "You are Audita, a narrow semantic-reversal validation assistant. Evaluate whether each proposed correction changes a word to its antonym or otherwise reverses the meaning of the full segment. Do not treat every word substitution as a problem; focus specifically on antonyms and meaning reversals."
|
|
user := "Review these proposed transcript corrections and decide whether each one avoids reversing the segment meaning.\n\n" +
|
|
"Rules:\n" +
|
|
"- Return one validation decision for every correction_index in the input.\n" +
|
|
"- Reject corrections that introduce antonyms or otherwise reverse the meaning of the original segment.\n" +
|
|
"- Reject examples like changing \"visible\" to \"invisible\" or \"up\" to \"down\" when that reverses the segment meaning.\n" +
|
|
"- Evaluate the full original_segment_text and corrected_segment_text, not only the replacement span.\n" +
|
|
"- Do not reject a correction merely because the literal written word changes.\n" +
|
|
"- Do not act as a general semantic-style reviewer; this validator is only a guard against antonyms and meaning reversals.\n" +
|
|
"- If a correction includes categories, treat them as additional segment context.\n" +
|
|
"- Each returned validation must contain only correction_index, approved, confidence, and reason.\n" +
|
|
"- confidence must be between 0.0 and 1.0.\n\n" +
|
|
promptcontext.TranscriptDescriptionBlock(transcriptDescription) +
|
|
fmt.Sprintf("Corrections to validate:\n%s", payloadJSON)
|
|
return []LLMMessage{{Role: "system", Content: system}, {Role: "user", Content: user}}, nil
|
|
}
|
|
|
|
func BuildEditorialMessages(validationPayload []LLMValidationItem, transcriptDescription string) ([]LLMMessage, error) {
|
|
payloadJSON, err := marshalPromptPayload(validationPayload)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
system := "You are Audita, a conservative editorial validation assistant. Evaluate whether each proposed correction is editorial in nature and preserves the segment's underlying meaning. Editorial revisions may include dysfluency cleanup, punctuation changes, capitalization changes, homophone or mistranscription corrections, and similar low-risk editorial cleanup."
|
|
user := "Review these proposed transcript corrections and decide whether each one is an acceptable editorial revision.\n\n" +
|
|
"Rules:\n" +
|
|
"- Return one validation decision for every correction_index in the input.\n" +
|
|
"- Approve editorial revisions that preserve the underlying meaning of the segment.\n" +
|
|
"- Approve dysfluency cleanup, including cleanup of repeated words, repeated short phrases, filler words, hesitation artifacts, and similar common spoken dysfluencies.\n" +
|
|
"- Approve punctuation, spacing, capitalization, and article cleanup when they preserve meaning.\n" +
|
|
"- Approve low-risk homophone or mistranscription corrections when they are contextually well supported.\n" +
|
|
"- Approve conservative combinations of these editorial changes when the overall revision remains meaning-preserving.\n" +
|
|
"- Reject repetition cleanup when the repetition plausibly serves urgency, excitement, insistence, or deliberate rhetorical emphasis rather than dysfluency.\n" +
|
|
"- Phrases such as \"Help! Help! Help!\", \"Stop! Stop! Stop!\", \"No! No! No!\", \"Yes! Yes! Yes!\", and \"Go! Go! Go!\" are often intentional emphasis and should usually be preserved.\n" +
|
|
"- Approve repetition cleanup only when local context supports it as accidental repetition, hesitation, or verbal restart.\n" +
|
|
"- Reject broad paraphrase, substantive semantic changes, substantive meaning changes, and revisions that materially change, obscure, distort, or reverse the segment's meaning.\n" +
|
|
"- Evaluate the full original_segment_text and corrected_segment_text, not only the replacement span.\n" +
|
|
"- If a correction includes categories, treat them as additional segment context.\n" +
|
|
"- Each returned validation must contain only correction_index, approved, confidence, and reason.\n" +
|
|
"- confidence must be between 0.0 and 1.0.\n\n" +
|
|
promptcontext.TranscriptDescriptionBlock(transcriptDescription) +
|
|
fmt.Sprintf("Corrections to validate:\n%s", payloadJSON)
|
|
return []LLMMessage{{Role: "system", Content: system}, {Role: "user", Content: user}}, nil
|
|
}
|
|
|
|
func BuildGrammarReviewMessages(validationPayload []LLMValidationItem, transcriptDescription string) ([]LLMMessage, error) {
|
|
return BuildEditorialMessages(validationPayload, transcriptDescription)
|
|
}
|
|
|
|
func BuildSpokenWordReviewMessages(validationPayload []LLMValidationItem, transcriptDescription string) ([]LLMMessage, error) {
|
|
return BuildEditorialMessages(validationPayload, transcriptDescription)
|
|
}
|
|
|
|
func marshalPromptPayload(validationPayload []LLMValidationItem) (string, error) {
|
|
payloadJSON, err := json.MarshalIndent(validationPayload, "", " ")
|
|
if err != nil {
|
|
return "", fmt.Errorf("marshal validation payload: %w", err)
|
|
}
|
|
return string(payloadJSON), nil
|
|
}
|