Documentation
¶
Index ¶
- type APIError
- type Agent
- type BatchHandle
- type File
- type ImageData
- type ImageOption
- type ImageRequest
- type ImageResponse
- type InputImage
- type MediaRef
- type Message
- type MiddlewareVetoError
- type Option
- func CacheTTL(d time.Duration) Option
- func WithCaching() Option
- func WithFrequencyPenalty(v float64) Option
- func WithHTTPClient(c *http.Client) Option
- func WithMaxTokens(n int) Option
- func WithMaxToolIterations(n int) Option
- func WithMiddleware(fns ...providers.MiddlewareFn) Option
- func WithPresencePenalty(v float64) Option
- func WithReasoningEffort(v string) Option
- func WithSeed(n int64) Option
- func WithStopSequences(seqs ...string) Option
- func WithTemperature(v float64) Option
- func WithThinkingBudget(n int) Option
- func WithTopK(n int) Option
- func WithTopP(v float64) Option
- type Part
- type Provider
- type Request
- type Response
- func Prompt(ctx context.Context, p Provider, req Request, opts ...Option) (Response, error)
- func PromptBatch(ctx context.Context, p Provider, reqs []Request, opts ...Option) ([]Response, error)
- func PromptStream(ctx context.Context, p Provider, req Request, callback StreamCallback, ...) (Response, error)
- func WaitBatch(ctx context.Context, handle BatchHandle, opts ...Option) ([]Response, error)
- type StreamCallback
- type Tool
- type Usage
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIError ¶
type APIError struct {
Provider string
StatusCode int
Type string
Message string
Retryable bool
RetryAfter time.Duration
}
APIError represents a provider API error.
type Agent ¶
type Agent struct {
// contains filtered or unexported fields
}
Agent manages multi-turn conversations with optional tool calling.
type BatchHandle ¶
BatchHandle represents an in-progress batch job.
func SubmitBatch ¶
func SubmitBatch(ctx context.Context, p Provider, reqs []Request, opts ...Option) (BatchHandle, error)
SubmitBatch submits a batch of requests and returns a handle for polling.
type ImageOption ¶ added in v0.2.0
type ImageOption func(*imageOptions)
ImageOption configures GenerateImage.
func WithAspectRatio ¶ added in v0.2.0
func WithAspectRatio(ratio string) ImageOption
WithAspectRatio constrains the output aspect ratio (e.g., "16:9"). The value must appear in ImageGenConfig(provider).Models[].AspectRatios for the requested model, otherwise GenerateImage returns ValidationError.
func WithImageHTTPClient ¶ added in v0.2.0
func WithImageHTTPClient(c *http.Client) ImageOption
WithImageHTTPClient overrides the http.Client used for the GenerateImage call.
func WithImageMiddleware ¶ added in v0.2.0
func WithImageMiddleware(fns ...providers.MiddlewareFn) ImageOption
WithImageMiddleware registers pre/post hooks that fire around the image generation request. Op is providers.OpImageGeneration. Pre-phase can veto.
func WithImageSize ¶ added in v0.2.0
func WithImageSize(size string) ImageOption
WithImageSize sets the output resolution (e.g., "1K", "2K", "4K", "512"). Same per-model whitelist enforcement as WithAspectRatio.
func WithIncludeText ¶ added in v0.2.0
func WithIncludeText() ImageOption
WithIncludeText asks the model to also emit text parts (captions, refusals) alongside images. Defaults to off — most callers want pure image output.
type ImageRequest ¶ added in v0.2.0
ImageRequest is the canonical image-generation request.
Model is required: image-generation models are explicit choices and the text-generation default (e.g., gemini-2.5-flash) does not generate images.
Input is provided in one of two mutually-exclusive forms:
- Prompt: terse sugar for the text-only hot path. Internally desugars to Parts: []Part{Text(Prompt)} before serialisation.
- Parts: canonical multimodal input. A positionally-ordered sequence of text and image parts; required for editing and compositional generation where caller-controlled ordering matters.
Pre-flight validation requires exactly one of Prompt or Parts to be non-empty (XOR). Image-typed parts respect ImageGenConfig.MaxInputCount.
type ImageResponse ¶ added in v0.2.0
ImageResponse is the canonical image-generation response.
func GenerateImage ¶ added in v0.2.0
func GenerateImage(ctx context.Context, p Provider, req ImageRequest, opts ...ImageOption) (ImageResponse, error)
GenerateImage produces one or more images from a text prompt, optionally conditioned on reference images for editing or composition. Input is either Prompt (sugar for the text-only case) or Parts (canonical multimodal sequence) — exactly one must be set. Pre-flight validation rejects unsupported aspect ratios, sizes, and image-part counts before any HTTP call.
type InputImage ¶ added in v0.2.0
type InputImage struct {
URL string // URL or base64 data URI
MimeType string
Detail string // "auto", "low", "high" (provider-specific)
}
InputImage references an image attached to a text-generation request (vision input). Distinct from Part's Image() constructor used for image-generation calls; the two concepts target different capabilities and the migration to a unified Part-based vocabulary for text generation is tracked separately (see ADR-008 OQ-2).
type MediaRef ¶ added in v0.2.0
MediaRef is an inline media payload (mime type + raw bytes). Reused by every Part variant that carries non-text content.
type MiddlewareVetoError ¶
type MiddlewareVetoError struct {
Cause error
}
MiddlewareVetoError wraps a pre-phase veto. Callers can errors.As against this type to discriminate a veto from a transport or provider error.
func (*MiddlewareVetoError) Error ¶
func (e *MiddlewareVetoError) Error() string
func (*MiddlewareVetoError) Unwrap ¶
func (e *MiddlewareVetoError) Unwrap() error
type Option ¶
type Option func(*options)
Option configures a Prompt or Agent call.
func CacheTTL ¶
CacheTTL sets the cache time-to-live. Used by resource caching (Google). Ignored by providers with automatic or explicit caching.
func WithCaching ¶
func WithCaching() Option
WithCaching enables prompt caching for providers that support it. Behavior depends on the provider's caching mode (automatic, explicit, or resource).
func WithFrequencyPenalty ¶
WithFrequencyPenalty sets the repetition penalty (-2.0 to 2.0).
func WithHTTPClient ¶
WithHTTPClient sets a custom HTTP client.
func WithMaxToolIterations ¶
WithMaxToolIterations sets the maximum tool call loop iterations for Agent.
func WithMiddleware ¶
func WithMiddleware(fns ...providers.MiddlewareFn) Option
WithMiddleware registers pre/post hooks that fire around LLM requests, tool calls, cache creation, uploads, and batch submits. Pre-phase middleware can veto an operation by returning a non-nil error. Post-phase return values are ignored (observation only). Middlewares fire in registration order.
func WithPresencePenalty ¶
WithPresencePenalty sets the diversity encouragement (-2.0 to 2.0).
func WithReasoningEffort ¶
WithReasoningEffort sets reasoning intensity ("low", "medium", "high").
func WithStopSequences ¶
WithStopSequences sets generation halt strings.
func WithTemperature ¶
WithTemperature sets the sampling temperature (0.0-2.0).
func WithThinkingBudget ¶
WithThinkingBudget sets the extended thinking token budget.
type Part ¶ added in v0.2.0
Part is the universal multimodal input atom. Exactly one of Text or Image is set; both empty or both set is invalid (rejected by pre-flight validation). Construct via the package-level Text() and Image() helpers.
type Provider ¶
type Provider struct {
Name string // "anthropic", "openai", "google", "grok"
APIKey string
Model string // optional, uses default if empty
BaseURL string // optional, overrides default API endpoint
}
Provider identifies an LLM provider with its API key and optional overrides.
type Request ¶
type Request struct {
System string // system prompt
User string // user message (for single-turn)
Messages []Message // conversation history (for multi-turn)
Schema string // JSON schema for structured output (optional)
Files []File // file attachments (optional)
Images []InputImage // image inputs (optional)
}
Request is the canonical request format (OpenAI-compatible shape).
type Response ¶
Response is the canonical response format.
func PromptBatch ¶
func PromptBatch(ctx context.Context, p Provider, reqs []Request, opts ...Option) ([]Response, error)
PromptBatch sends multiple requests as a batch and blocks until all results are ready. Uses the provider's batch config from the ontology to determine input mode and lifecycle.
func PromptStream ¶
func PromptStream(ctx context.Context, p Provider, req Request, callback StreamCallback, opts ...Option) (Response, error)
PromptStream sends a streaming request, calling back with each text chunk. Returns the final response with accumulated text and usage. Middleware fires exactly once pre-phase and once post-phase, bracketing the whole stream. Usage in post-phase is the accumulated total at stream close.
type StreamCallback ¶
type StreamCallback func(chunk string)
StreamCallback is called with each text chunk during streaming.
type Tool ¶
type Tool struct {
Name string
Description string
Schema map[string]any
Run func(map[string]any) (string, error)
}
Tool defines a callable function for the agent.
type Usage ¶
Usage holds token consumption metrics. Aliased to providers.Usage so middleware events and the public API share one type without conversion.
type ValidationError ¶
ValidationError represents a request validation error.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
llmkit
command
|
|
|
examples
|
|
|
image-gen
command
Example: text-to-image generation against Google's Nano Banana 2 (Gemini 3.1 Flash Image), with a follow-up edit pass that uses the first output as a reference image.
|
Example: text-to-image generation against Google's Nano Banana 2 (Gemini 3.1 Flash Image), with a follow-up edit pass that uses the first output as a reference image. |
|
middleware
command
Example: spend-cap middleware.
|
Example: spend-cap middleware. |