stream

package
v0.0.0-beta Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package stream provides streaming output for chat completions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Func

type Func func(thinking, content string, done bool) error

Func is the callback for streaming content during chat completion.

type Option

type Option func(*Streamer)

Option configures a Streamer.

func WithContentStyle

func WithContentStyle(style *color.Color) Option

WithContentStyle sets the color style for content output.

func WithDefaultStyles

func WithDefaultStyles() Option

WithDefaultStyles applies the default color scheme.

func WithNoStream

func WithNoStream() Option

WithNoStream disables streaming entirely.

func WithPreamble

func WithPreamble(preamble string) Option

WithPreamble sets text to display before streaming begins.

func WithPreambleStyle

func WithPreambleStyle(style *color.Color) Option

WithPreambleStyle sets the color style for the preamble.

func WithThinkingStyle

func WithThinkingStyle(style *color.Color) Option

WithThinkingStyle sets the color style for thinking output.

func WithVerbose

func WithVerbose(show bool) Option

WithVerbose controls whether thinking output is displayed.

type Spinner

type Spinner interface {
	Start()
	Stop()
}

type StreamResult

type StreamResult struct {
	Func Func
	Stop func()
}

StreamResult holds the stream callback and cleanup function.

type Streamer

type Streamer struct {
	// Verbose controls whether thinking/reasoning output is displayed.
	Verbose bool
	// ThinkingStyle is the color style for thinking output.
	ThinkingStyle *color.Color
	// ContentStyle is the color style for content output.
	ContentStyle *color.Color
	// Preamble is text to display before streaming starts.
	Preamble string
	// PreambleStyle is the color style for the preamble.
	PreambleStyle *color.Color
	// Nil disables streaming entirely.
	Nil bool
}

Streamer handles formatted streaming output with optional thinking display.

func New

func New(options ...Option) *Streamer

New creates a Streamer with the given options.

func (*Streamer) Stream

func (s *Streamer) Stream(sp Spinner) StreamResult

Jump to

Keyboard shortcuts

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