Documentation
¶
Overview ¶
Package cloud is the client for the cloudproto protocol (see ai/cloudproto): it implements ai.LLMProvider (chat) and exposes a separate decision.Provider via Decider(), plus a Usage lookup.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client implements ai.LLMProvider (Name "cloud"). Its decision.Provider role is a SEPARATE value returned by Decider() (Name "cloud-decision"): Go dispatches one Name() per concrete type, so a single type cannot report two different names to two different interfaces, and Decider() is how that split is actually satisfied.
func New ¶
New builds a Client. It panics if BaseURL or Token is unset, and normalises BaseURL to always end with "/".
func (*Client) Decider ¶
Decider returns c's decision.Provider role (Name "cloud-decision"), backed by POST ai/decision. It also implements the optional `DecisionTimeout() time.Duration` interface decision.Chain honours, so a remote decision call gets more time than Chain's local-call default.
func (*Client) Stream ¶
Stream implements ai.LLMProvider by POSTing ai/chat and parsing the SSE response with cloudproto.ReadEvents.
Fatal-error contract (see ai.LLMProvider doc): every fatal condition yields exactly one final (ai.Event{Type: ai.EventError, Error: e}, e) and returns; EventStarted is only yielded once the HTTP request has actually succeeded. cloudproto.ReadEvents already conforms (an EventError frame, a transport error, or an unterminated stream are all fatal there too), so Stream relays its events unchanged EXCEPT that a mid-stream failure caused by ctx being done (the body read was interrupted by cancellation, not a genuine transport/upstream fault) is remapped to ErrCodeCanceled here -- cloudproto has no ctx of its own to make that distinction itself.
func (*Client) Usage ¶
func (c *Client) Usage(ctx context.Context) (cloudproto.UsageResponse, error)
Usage calls GET ai/usage.
type Config ¶
type Config struct {
// BaseURL is the API base URL including its version prefix, e.g.
// "https://api.example.com/v0/". A trailing slash is added if missing.
// The product supplies this (see ai/aiconfig); this package has no
// default of its own.
BaseURL string
// Product identifies the consuming product for metering/limits/routing
// and is sent as the X-AI-Product header and ai.ChatRequest.Product /
// decision.Request.Product.
Product string
// Token returns the bearer token for each request.
Token func(context.Context) (string, error)
HTTPClient *http.Client
}
Config configures a Client.