utils

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

README

Utils

Package utils provides shared utilities: backoff, notifier, sentence-boundary detection, and text/pattern aggregation for LLM streams.

Purpose

  • backoff: Exponential backoff for retries/reconnection (e.g. WebSocket).
  • notifier: One-shot signal: one goroutine waits, another notifies (Wait/Notify).
  • sentence: Sentence-end detection (e.g. .!?) for aggregating text.
  • patternaggregator: Delimiter-based aggregation (e.g. ``) to extract tagged content from LLM output (IVR, DTMF).
  • textaggregator: Interface and implementations to aggregate incremental text (e.g. LLM tokens) into segments (e.g. sentences).

Utility tree

graph TD
    Root["utils"] --> Backoff["backoff\nExponentialBackoff\nBackoffCap"]
    Root --> Notifier["notifier\nNotifier\nWait / Notify"]
    Root --> Sentence["sentence\nMatchEndOfSentence\nDefaultSentenceEnd"]
    Root --> PatternAgg["patternaggregator\nAggregator\nFeed / Flush\nMatch"]
    Root --> TextAgg["textaggregator\nAggregator interface\nSegment\nsentence impl"]

Exported symbols (root)

Symbol Type Description
BackoffCap const Max duration (60s) for ExponentialBackoff
ExponentialBackoff(attempt) func Returns 2^attempt seconds, capped at BackoffCap; attempt 1-based

Subpackages

Path Exported symbols Description
notifier Notifier, New, Notify, Wait One waiter unblocked per Notify; safe for concurrent use
sentence DefaultSentenceEnd, MatchEndOfSentence(s, endChars) Reports if trimmed s ends with sentence-ending rune
patternaggregator Match, Aggregator, New(open, close), Feed, Flush Emits text segments and delimiter matches from stream
textaggregator Segment, Aggregator (interface: Aggregate, Flush, Reset, HandleInterruption) Aggregate incremental text into segments; sentence implementation

Concurrency

  • backoff: Stateless; safe for concurrent use.
  • notifier: Notify and Wait are safe for concurrent use; mutex protects the channel.
  • sentence: Stateless; safe for concurrent use.
  • patternaggregator: Aggregator is not safe for concurrent use; one caller should Feed/Flush.
  • textaggregator: Implementations are typically single-threaded per aggregator instance.

Files

File Description
backoff.go BackoffCap, ExponentialBackoff
notifier/notifier.go Notifier, New, Notify, Wait
sentence/sentence.go DefaultSentenceEnd, MatchEndOfSentence
patternaggregator/patternaggregator.go Match, Aggregator, New, Feed, Flush
textaggregator/textaggregator.go Segment, Aggregator interface
textaggregator/sentence.go Sentence-based aggregator implementation

See also

Documentation

Overview

Package utils provides shared utilities (backoff, etc.).

Index

Constants

View Source
const (
	// BackoffCap is the maximum duration returned by ExponentialBackoff.
	BackoffCap = 60 * time.Second
)

Variables

This section is empty.

Functions

func ExponentialBackoff

func ExponentialBackoff(attempt int) time.Duration

ExponentialBackoff returns a duration for the given attempt (1-based). Duration is 2^attempt seconds, capped at BackoffCap. Used for reconnection backoff in websocket and other retry logic.

Types

This section is empty.

Directories

Path Synopsis
Package notifier provides a simple signal that one goroutine can wait on and another can trigger.
Package notifier provides a simple signal that one goroutine can wait on and another can trigger.
Package patternaggregator provides XML-style tag aggregation for LLM text streams.
Package patternaggregator provides XML-style tag aggregation for LLM text streams.
Package sentence provides helpers for sentence-boundary detection in aggregated text.
Package sentence provides helpers for sentence-boundary detection in aggregated text.
Package textaggregator provides an interface and implementations for aggregating incremental text (e.g.
Package textaggregator provides an interface and implementations for aggregating incremental text (e.g.

Jump to

Keyboard shortcuts

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