sse

package
v0.0.25 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package sse provides a reader for Server-Sent Events (SSE) streams.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EventReader

type EventReader[T any] struct {
	// contains filtered or unexported fields
}

EventReader streams events dynamically from an OpenAI endpoint.

func NewEventReader

func NewEventReader[T any](r io.ReadCloser) *EventReader[T]

NewEventReader creates an EventReader that provides access to messages of type T from r.

func (*EventReader[T]) Close

func (er *EventReader[T]) Close() error

Close closes the EventReader and any applicable inner stream state.

func (*EventReader[T]) Read

func (er *EventReader[T]) Read() (T, error)

Read reads the next event from the stream. Returns io.EOF when there are no further events.

type MockEventReader

type MockEventReader[T any] struct {
	// contains filtered or unexported fields
}

MockEventReader is a mock implementation of the sse.EventReader. This lets us use EventReader as a common interface for models that support streaming (like gpt-4o) and models that do not (like the o1 class of models).

func NewMockEventReader

func NewMockEventReader[T any](events []T) *MockEventReader[T]

NewMockEventReader creates a new MockEventReader with the given events.

func (*MockEventReader[T]) Close

func (mer *MockEventReader[T]) Close() error

Close closes the Reader and any applicable inner stream state.

func (*MockEventReader[T]) Read

func (mer *MockEventReader[T]) Read() (T, error)

Read reads the next event from the stream.

type Reader

type Reader[T any] interface {
	// Read reads the next event from the stream.
	// Returns io.EOF when there are no further events.
	Read() (T, error)
	// Close closes the Reader and any applicable inner stream state.
	Close() error
}

Reader is an interface for reading events from an SSE stream.

Jump to

Keyboard shortcuts

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