streams

package
v0.9.5 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package streams contains the interfaces for groq-go streamed responses.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultErrorAccumulator

type DefaultErrorAccumulator struct {
	Buffer groqerr.ErrorBuffer
}

DefaultErrorAccumulator is a default implementation of ErrorAccumulator

func (*DefaultErrorAccumulator) Bytes

func (e *DefaultErrorAccumulator) Bytes() (errBytes []byte)

Bytes method returns the bytes of the error accumulator.

func (*DefaultErrorAccumulator) Write

func (e *DefaultErrorAccumulator) Write(p []byte) error

Write method writes bytes to the error accumulator.

type ErrorAccumulator

type ErrorAccumulator interface {
	// Write method writes bytes to the error accumulator
	//
	// It implements the io.Writer interface.
	Write(p []byte) error
	// Bytes method returns the bytes of the error accumulator.
	Bytes() []byte
}

ErrorAccumulator is an interface for a unit that accumulates errors.

func NewErrorAccumulator

func NewErrorAccumulator() ErrorAccumulator

NewErrorAccumulator creates a new error accumulator

type StreamReader

type StreamReader[T any] struct {
	Reader *bufio.Reader

	ErrAccumulator ErrorAccumulator
	Header         http.Header // Header is the header of the response.
	// contains filtered or unexported fields
}

StreamReader is a stream reader.

func NewStreamReader

func NewStreamReader[Q any, T Streamer[Q]](
	readCloser io.ReadCloser,
	header map[string][]string,
	emptyMessagesLimit uint,
) *StreamReader[T]

NewStreamReader creates a new stream reader.

func (*StreamReader[T]) Close

func (stream *StreamReader[T]) Close() error

Close closes the stream.

func (*StreamReader[T]) Recv

func (stream *StreamReader[T]) Recv() (response T, err error)

Recv receives a response from the stream.

func (*StreamReader[T]) UnmarshalError

func (stream *StreamReader[T]) UnmarshalError() (errResp *groqerr.ErrorResponse)

UnmarshalError unmarshals the error response.

type Streamer

type Streamer[T any] interface {
	*T
}

Streamer is an interface for a Streamer.

Jump to

Keyboard shortcuts

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