provider

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package provider holds what the model clients share and no provider's rules: the HTTP request, the server-sent event reader, the stream of response chunks, the error of an HTTP failure, and its telemetry.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrIncompleteStream is a stream that closed before its terminal event.
	ErrIncompleteStream = errors.New("incomplete provider stream")
	// ErrMalformedStream is a stream event that is not valid JSON.
	ErrMalformedStream = errors.New("malformed provider stream")
)

Functions

func EmitFailed

func EmitFailed(ctx context.Context, err error, httpStatus int, inputItems string)

EmitFailed records a failed model request as a span-correlated log event. inputItems summarizes the request's input for diagnosis.

func Post

func Post(ctx context.Context, client *http.Client, url string, header http.Header, body []byte) (*http.Response, error)

Post sends body as JSON to url with header. A transport failure wraps tacklr.ErrNetwork. The caller closes the response body.

func Retryable

func Retryable(status int) bool

Retryable reports a status the durable runtime retries: a timeout, a rate limit, or a server failure.

Types

type APIStatusError

type APIStatusError struct {
	Status int
	Body   string
	Code   string
}

APIStatusError is an HTTP error answer from a model API. Find it in a wrapped chain with errors.As.

func (*APIStatusError) Error

func (e *APIStatusError) Error() string

func (*APIStatusError) ProviderErrorCode

func (e *APIStatusError) ProviderErrorCode() string

ProviderErrorCode implements telemetry.ProviderStatus.

func (*APIStatusError) ProviderHTTPStatus

func (e *APIStatusError) ProviderHTTPStatus() int

ProviderHTTPStatus implements telemetry.ProviderStatus.

type Chunks

type Chunks struct {
	C chan tacklr.LLMResponseChunk
	// contains filtered or unexported fields
}

Chunks is a stream of response chunks that stops sending once its context ends, so a client goroutine never blocks on a reader that left.

func NewChunks

func NewChunks(ctx context.Context) Chunks

NewChunks is a stream for one request on ctx.

func (Chunks) Fail

func (c Chunks) Fail(err error)

Fail ends the stream with err.

func (Chunks) Send

func (c Chunks) Send(chunk tacklr.LLMResponseChunk) bool

Send delivers chunk, or gives up when the context ends while the reader does not take it. It is false when it gave up.

type SSE

type SSE struct {
	// contains filtered or unexported fields
}

SSE reads the data payloads of a server-sent event stream, one line each. Other lines (event names, comments, blank lines) are skipped.

func NewSSE

func NewSSE(r io.Reader) *SSE

NewSSE reads r, with lines up to 2 MiB.

func (*SSE) Err

func (s *SSE) Err() error

Err is the read error that ended the stream, if any.

func (*SSE) Next

func (s *SSE) Next() (string, bool)

Next is the next data payload, or false at the end of the stream.

Jump to

Keyboard shortcuts

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