cloud

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

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

func New(cfg Config) *Client

New builds a Client. It panics if BaseURL or Token is unset, and normalises BaseURL to always end with "/".

func (*Client) Decider

func (c *Client) Decider() decision.Provider

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) Name

func (c *Client) Name() string

Name implements ai.LLMProvider.

func (*Client) Stream

func (c *Client) Stream(ctx context.Context, req ai.ChatRequest) iter.Seq2[ai.Event, error]

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

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.

Jump to

Keyboard shortcuts

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