Documentation
¶
Overview ¶
Package llmclient provides provider-neutral buffered and streaming HTTP execution without importing gateway or agent-runtime concerns.
Index ¶
- Variables
- func MergeBodyDefaults(body json.RawMessage, defaults map[string]json.RawMessage) (json.RawMessage, error)
- type AWSCredentials
- type AWSCredentialsProvider
- type AWSCredentialsProviderFunc
- type AuthFunc
- type Authenticator
- type Backend
- type CallMetadata
- type CallResult
- type Client
- func (c *Client) Call(ctx context.Context, backend Backend, request llmprotocol.Request) (CallResult, error)
- func (c *Client) Embed(ctx context.Context, backend Backend, request llmprotocol.EmbeddingRequest) (EmbeddingCallResult, error)
- func (c *Client) Stream(ctx context.Context, backend Backend, request llmprotocol.Request) (*Stream, error)
- type EmbeddingCallResult
- type Error
- type ErrorKind
- type Options
- type RetryPolicy
- type SigV4Authenticator
- type Stream
- type UnauthorizedRecoverer
Constants ¶
This section is empty.
Variables ¶
var ( ErrFirstEventTimeout = errors.New("llm client first stream event timeout") ErrStreamIdleTimeout = errors.New("llm client stream idle timeout") )
Functions ¶
func MergeBodyDefaults ¶
func MergeBodyDefaults(body json.RawMessage, defaults map[string]json.RawMessage) (json.RawMessage, error)
MergeBodyDefaults shallow-merges bounded provider-specific defaults into an encoded request object. Fields already present in body always win. This helper is exported so gateways that retain ownership of raw HTTP proxying can share the same validation and merge semantics as Client.
Types ¶
type AWSCredentials ¶
type AWSCredentials struct {
AccessKeyID string
SecretAccessKey string
SessionToken string
ExpiresAt time.Time
}
AWSCredentials is the minimal material required for SigV4. The client never discovers, refreshes, persists, or logs this value.
type AWSCredentialsProvider ¶
type AWSCredentialsProvider interface {
Retrieve(context.Context) (AWSCredentials, error)
}
AWSCredentialsProvider lets a host integrate static credentials, an AWS SDK chain, workload identity, or another refresh mechanism without coupling this module to that policy.
func StaticAWSCredentials ¶
func StaticAWSCredentials(credentials AWSCredentials) AWSCredentialsProvider
type AWSCredentialsProviderFunc ¶
type AWSCredentialsProviderFunc func(context.Context) (AWSCredentials, error)
func (AWSCredentialsProviderFunc) Retrieve ¶
func (f AWSCredentialsProviderFunc) Retrieve(ctx context.Context) (AWSCredentials, error)
type Authenticator ¶
func APIKeyHeader ¶
func APIKeyHeader(name, value string) Authenticator
func BearerToken ¶
func BearerToken(token string) Authenticator
type Backend ¶
type Backend struct {
Name string
Format llmprotocol.Format
BaseURL string
Path string
StreamPath string
BatchPath string
Model string
Headers map[string]string
BodyDefaults map[string]json.RawMessage
Auth Authenticator
}
type CallMetadata ¶
type CallMetadata struct {
BackendName string
Format llmprotocol.Format
Endpoint string
StatusCode int
Attempts int
StartedAt time.Time
Duration time.Duration
ResponseHeaders http.Header
RequestDiagnostics []llmprotocol.Diagnostic
ResponseDiagnostics []llmprotocol.Diagnostic
}
type CallResult ¶
type CallResult struct {
Response llmprotocol.Response
Metadata CallMetadata
}
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) Call ¶
func (c *Client) Call(ctx context.Context, backend Backend, request llmprotocol.Request) (CallResult, error)
func (*Client) Embed ¶
func (c *Client) Embed(ctx context.Context, backend Backend, request llmprotocol.EmbeddingRequest) (EmbeddingCallResult, error)
Embed executes one buffered embeddings request. Batch cardinality is derived from request.Inputs; each response Data item may independently contain a rank-one or rank-two tensor.
type EmbeddingCallResult ¶
type EmbeddingCallResult struct {
Response llmprotocol.EmbeddingResponse
Metadata CallMetadata
}
type Error ¶
type ErrorKind ¶
type ErrorKind string
const ( ErrorInvalidConfig ErrorKind = "invalid_config" ErrorAuthentication ErrorKind = "authentication" ErrorEncode ErrorKind = "encode" ErrorTransport ErrorKind = "transport" ErrorTimeout ErrorKind = "timeout" ErrorCanceled ErrorKind = "canceled" ErrorUpstream ErrorKind = "upstream" ErrorResponseLimit ErrorKind = "response_limit" ErrorDecode ErrorKind = "decode" ErrorStream ErrorKind = "stream" )
type Options ¶
type Options struct {
HTTPClient *http.Client
Registry *codec.Registry
EmbeddingRegistry *codec.EmbeddingRegistry
Policy llmprotocol.Policy
MaxResponseBytes int64
FirstEventTimeout time.Duration
StreamIdleTimeout time.Duration
MaxStreamLineBytes int
IncludeStreamUsage *bool
UserAgent string
Retry RetryPolicy
}
type RetryPolicy ¶
type SigV4Authenticator ¶
type SigV4Authenticator struct {
Region string
Service string
Credentials AWSCredentialsProvider
Clock func() time.Time
}
SigV4Authenticator signs the final HTTP request, including its escaped path and encoded body. Service defaults to "bedrock". Clock is intended for deterministic tests; production callers should leave it nil.
type Stream ¶
type Stream struct {
// contains filtered or unexported fields
}
func (*Stream) Metadata ¶
func (s *Stream) Metadata() CallMetadata
func (*Stream) Next ¶
func (s *Stream) Next(ctx context.Context) (llmprotocol.StreamEvent, error)
func (*Stream) Response ¶
func (s *Stream) Response() llmprotocol.Response
type UnauthorizedRecoverer ¶ added in v0.3.0
type UnauthorizedRecoverer interface {
}
UnauthorizedRecoverer is an optional capability implemented by dynamic authenticators. When an upstream rejects a request with HTTP 401, Client asks the authenticator to refresh or otherwise recover its credentials, then replays the request exactly once. Static authenticators need only implement Authenticator.