Documentation
¶
Overview ¶
Package streaming provides utilities for streaming responses from AI providers.
Package streaming provides error types and utilities for streaming responses.
Index ¶
- type ByteTrackingStream
- func (b *ByteTrackingStream) BytesRead() int64
- func (b *ByteTrackingStream) BytesWritten() int64
- func (b *ByteTrackingStream) Close() error
- func (b *ByteTrackingStream) HasMismatch() bool
- func (b *ByteTrackingStream) MarkBytesWritten(n int64)
- func (b *ByteTrackingStream) Next() (types.ChatCompletionChunk, error)
- type ErrorType
- type StreamError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ByteTrackingStream ¶
type ByteTrackingStream struct {
// contains filtered or unexported fields
}
ByteTrackingStream wraps a ChatCompletionStream and tracks bytes read vs bytes written. It helps detect data corruption or loss during streaming by comparing the raw bytes read from the stream with the bytes written to the client.
func NewByteTrackingStream ¶
func NewByteTrackingStream(stream types.ChatCompletionStream) *ByteTrackingStream
NewByteTrackingStream creates a new ByteTrackingStream that wraps the given stream.
func (*ByteTrackingStream) BytesRead ¶
func (b *ByteTrackingStream) BytesRead() int64
BytesRead returns the number of bytes read from the stream.
func (*ByteTrackingStream) BytesWritten ¶
func (b *ByteTrackingStream) BytesWritten() int64
BytesWritten returns the number of bytes written (set externally).
func (*ByteTrackingStream) Close ¶
func (b *ByteTrackingStream) Close() error
Close closes the underlying stream.
func (*ByteTrackingStream) HasMismatch ¶
func (b *ByteTrackingStream) HasMismatch() bool
HasMismatch returns true if there is a mismatch between bytes read and written. Allows 1-byte tolerance for trailing newline.
func (*ByteTrackingStream) MarkBytesWritten ¶
func (b *ByteTrackingStream) MarkBytesWritten(n int64)
MarkBytesWritten sets the number of bytes written.
func (*ByteTrackingStream) Next ¶
func (b *ByteTrackingStream) Next() (types.ChatCompletionChunk, error)
Next returns the next chunk from the stream and tracks bytes.
type StreamError ¶
StreamError represents an error during streaming
func MakeStreamError ¶
func MakeStreamError(err error) StreamError
MakeStreamError creates a StreamError from an error
func (StreamError) ToSSEEvent ¶
func (se StreamError) ToSSEEvent() string
ToSSEEvent converts the StreamError to an SSE event string Format: event: error\ndata: {"type":"...","message":"..."}\n\n