Collect optional validation context only when it can fit
This commit is contained in:
@@ -60,6 +60,7 @@ func (v *LLMBackedValidator) Validate(ctx context.Context, req Request) (Result,
|
||||
if req.LLMClient == nil {
|
||||
return Result{}, fmt.Errorf("LLM-backed validator %q requires a structured LLM client", v.name)
|
||||
}
|
||||
req.Section = req.sectionLookup()
|
||||
items, immediate := buildValidationItems(req)
|
||||
if len(items) == 0 {
|
||||
all := append([]Decision(nil), immediate...)
|
||||
@@ -75,7 +76,7 @@ func (v *LLMBackedValidator) Validate(ctx context.Context, req Request) (Result,
|
||||
maxTokens = req.Settings.Validation.MaxPromptTokens
|
||||
}
|
||||
|
||||
batches, oversized, err := prepareValidationBatches(items, maxTokens, v.estimator)
|
||||
batches, oversized, err := prepareValidationBatches(items, maxTokens, v.estimator, validationContextFor(req))
|
||||
operations := make([]outcomes.Operation, 0)
|
||||
llmDecisions := make([]Decision, 0)
|
||||
partialResult := func() Result {
|
||||
@@ -253,13 +254,6 @@ func buildValidationItems(req Request) ([]LLMValidationItem, []Decision) {
|
||||
immediate := make([]Decision, 0)
|
||||
req.Section = req.sectionLookup()
|
||||
segments := req.Section.segments
|
||||
var glossary glossaryContext
|
||||
if req.GlossaryView != nil {
|
||||
glossary = req.GlossaryView.context
|
||||
} else {
|
||||
glossary = prepareGlossaryContext(req.Glossary)
|
||||
}
|
||||
|
||||
for _, p := range req.CandidateProposal {
|
||||
position, ok := req.Section.Position(p.TargetSegmentID)
|
||||
if !ok {
|
||||
@@ -274,8 +268,8 @@ func buildValidationItems(req Request) ([]LLMValidationItem, []Decision) {
|
||||
continue
|
||||
}
|
||||
|
||||
neighbors, glossaryEntries := glossary.validationContext(segments, position, preview.CorrectedSegmentText)
|
||||
items = append(items, LLMValidationItem{
|
||||
segmentPosition: position,
|
||||
CorrectionIndex: p.ProposalIndex,
|
||||
Speaker: seg.Speaker,
|
||||
OriginalText: p.OriginalText,
|
||||
@@ -283,8 +277,6 @@ func buildValidationItems(req Request) ([]LLMValidationItem, []Decision) {
|
||||
OriginalSegmentText: seg.Text,
|
||||
CorrectedSegmentText: preview.CorrectedSegmentText,
|
||||
Categories: append([]string(nil), seg.Categories...),
|
||||
NeighboringSegments: neighbors,
|
||||
GlossaryEntries: glossaryEntries,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user