Documentation
¶
Overview ¶
Package rest provides a generic REST API generator for Augustus.
This package implements the Generator interface for making HTTP requests to REST APIs. It supports configurable endpoints, HTTP methods, request templates with variable substitution, and flexible response parsing including JSONPath.
Index ¶
- func NewRest(cfg registry.Config) (generators.Generator, error)
- type Config
- type Option
- func WithAPIKey(key string) Option
- func WithHeaders(headers map[string]string) Option
- func WithMethod(method string) Option
- func WithRateLimit(rps float64) Option
- func WithRateLimitCodes(codes map[int]bool) Option
- func WithReqTemplate(template string) Option
- func WithRequestTimeout(timeout time.Duration) Option
- func WithResponseJSON(parseJSON bool) Option
- func WithResponseJSONField(field string) Option
- func WithSSEFilterField(field string) Option
- func WithSSEFilterValue(value string) Option
- func WithSSEMode(mode string) Option
- func WithSSETextField(field string) Option
- func WithSkipCodes(codes map[int]bool) Option
- func WithURI(uri string) Option
- type Rest
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
// Required
URI string
// Optional with defaults
Method string
Headers map[string]string
ReqTemplate string
ResponseJSON bool
ResponseJSONField string
RequestTimeout time.Duration
RateLimitCodes map[int]bool
SkipCodes map[int]bool
APIKey string
RateLimit float64 // Requests per second (0 = unlimited)
// SSE configuration (optional, enables configurable SSE parsing)
SSETextField string // JSONPath for text extraction from SSE events (e.g., "$.content.text")
SSEMode string // "delta" (concat all chunks) or "last" (take last non-empty value)
SSEFilterField string // JSONPath for filtering SSE events (e.g., "$.content.type")
SSEFilterValue string // Value to match for sse_filter_field (e.g., "CHAT_TEXT")
}
Config holds typed configuration for the REST generator.
func ApplyOptions ¶
ApplyOptions applies functional options to a Config.
func ConfigFromMap ¶
ConfigFromMap parses a registry.Config map into a typed Config.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a Config with sensible defaults.
type Option ¶
Option is a functional option for Config.
func WithHeaders ¶
WithHeaders sets the HTTP headers.
func WithRateLimit ¶
WithRateLimit sets the rate limit in requests per second.
func WithRateLimitCodes ¶
WithRateLimitCodes sets the rate limit HTTP status codes.
func WithReqTemplate ¶
WithReqTemplate sets the request template.
func WithRequestTimeout ¶
WithRequestTimeout sets the request timeout.
func WithResponseJSON ¶
WithResponseJSON sets whether to parse JSON responses.
func WithResponseJSONField ¶
WithResponseJSONField sets the JSON field to extract.
func WithSSEFilterField ¶ added in v0.0.9
WithSSEFilterField sets the JSONPath for filtering SSE events.
func WithSSEFilterValue ¶ added in v0.0.9
WithSSEFilterValue sets the value to match for the SSE filter field.
func WithSSEMode ¶ added in v0.0.9
WithSSEMode sets the SSE accumulation mode ("delta" or "last").
func WithSSETextField ¶ added in v0.0.9
WithSSETextField sets the JSONPath for text extraction from SSE events.
func WithSkipCodes ¶
WithSkipCodes sets the HTTP status codes to skip (return empty response).
type Rest ¶
type Rest struct {
// contains filtered or unexported fields
}
Rest is a generic REST API generator that makes HTTP requests to configured endpoints. It supports request templating, JSON response parsing, and various HTTP methods.
func (*Rest) ClearHistory ¶
func (r *Rest) ClearHistory()
ClearHistory is a no-op for REST generator (stateless).
func (*Rest) Description ¶
Description returns a human-readable description.
func (*Rest) Generate ¶
func (r *Rest) Generate(ctx context.Context, conv *attempt.Conversation, n int) ([]attempt.Message, error)
Generate sends the conversation's last prompt to the REST API and returns responses.
func (*Rest) LastRawResponse ¶ added in v0.0.9
LastRawResponse returns the raw HTTP response body from the most recent API call. This implements the hooks.RawResponseProvider interface.