textaggregator

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 16, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package textaggregator provides an interface and implementations for aggregating incremental text (e.g. LLM tokens) into segments (e.g. sentences).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Aggregator

type Aggregator interface {
	// Aggregate appends text and returns any complete segments. Caller may get 0, 1, or more.
	Aggregate(text string) []Segment
	// Flush returns any remaining buffered text as a single segment and clears the buffer.
	Flush() *Segment
	// Reset clears state without emitting.
	Reset()
	// HandleInterruption clears state (e.g. on barge-in).
	HandleInterruption()
}

Aggregator consumes incremental text and yields complete segments (e.g. by sentence).

type Segment

type Segment struct {
	Text string
	Type string
}

Segment is one emitted aggregation (text and type label).

type SentenceAggregator

type SentenceAggregator struct {
	SentenceEnd string
	MaxRunes    int
	// contains filtered or unexported fields
}

SentenceAggregator emits a segment when a sentence-ending rune is seen or max runes reached.

func NewSentenceAggregator

func NewSentenceAggregator(sentenceEnd string, maxRunes int) *SentenceAggregator

NewSentenceAggregator returns a sentence-based aggregator. sentenceEnd defaults to ".!?"; maxRunes 0 = no limit.

func (*SentenceAggregator) Aggregate

func (s *SentenceAggregator) Aggregate(text string) []Segment

Aggregate appends text and returns complete sentence segments.

func (*SentenceAggregator) Flush

func (s *SentenceAggregator) Flush() *Segment

Flush returns remaining buffer as one segment and resets.

func (*SentenceAggregator) HandleInterruption

func (s *SentenceAggregator) HandleInterruption()

HandleInterruption clears the buffer.

func (*SentenceAggregator) Reset

func (s *SentenceAggregator) Reset()

Reset clears the buffer without emitting.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL