Measure only the usable validation context prefix
This commit is contained in:
@@ -3,7 +3,6 @@ package validators
|
||||
import (
|
||||
"slices"
|
||||
|
||||
"gitea.maximumdirect.net/eric/audita/v3/internal/core/chunking"
|
||||
"gitea.maximumdirect.net/eric/audita/v3/internal/core/glossary"
|
||||
"gitea.maximumdirect.net/eric/audita/v3/internal/core/schema"
|
||||
)
|
||||
@@ -64,24 +63,6 @@ func (view glossaryContext) validationContext(segments []schema.Segment, positio
|
||||
return neighbors, entries
|
||||
}
|
||||
|
||||
// fitValidationContext drops optional context before treating required candidate
|
||||
// text as oversized. Glossary definitions take priority over adjacent segments.
|
||||
func fitValidationContext(item LLMValidationItem, budget int, estimator chunking.TokenEstimator) LLMValidationItem {
|
||||
for {
|
||||
tokens, err := estimateBatchTokens(estimator, []LLMValidationItem{item})
|
||||
if err != nil || tokens <= budget {
|
||||
return item
|
||||
}
|
||||
if len(item.NeighboringSegments) > 0 {
|
||||
item.NeighboringSegments = item.NeighboringSegments[:len(item.NeighboringSegments)-1]
|
||||
} else if len(item.GlossaryEntries) > 0 {
|
||||
item.GlossaryEntries = item.GlossaryEntries[:len(item.GlossaryEntries)-1]
|
||||
} else {
|
||||
return item
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func neighboringSegment(position string, segment schema.Segment) NeighboringSegment {
|
||||
return NeighboringSegment{Position: position, Speaker: segment.Speaker, Text: segment.Text, Categories: segment.Categories}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user