Documentation
¶
Index ¶
- Variables
- func Paginate[T any](ctx context.Context, client *Client, initialPage *Page[T]) (<-chan []T, <-chan error)
- type APIError
- type Backoff
- type Client
- func (r *Client) CancelTraining(ctx context.Context, trainingID string) (*Training, error)
- func (r *Client) CreatePrediction(ctx context.Context, version string, input PredictionInput, webhook *Webhook, ...) (*Prediction, error)
- func (r *Client) CreateTraining(ctx context.Context, model_owner string, model_name string, version string, ...) (*Training, error)
- func (r *Client) GetCollection(ctx context.Context, slug string) (*Collection, error)
- func (r *Client) GetModel(ctx context.Context, modelOwner string, modelName string) (*Model, error)
- func (r *Client) GetModelVersion(ctx context.Context, modelOwner string, modelName string, versionID string) (*ModelVersion, error)
- func (r *Client) GetPrediction(ctx context.Context, id string) (*Prediction, error)
- func (r *Client) GetTraining(ctx context.Context, trainingID string) (*Training, error)
- func (r *Client) ListCollections(ctx context.Context) (*Page[Collection], error)
- func (r *Client) ListModelVersions(ctx context.Context, modelOwner string, modelName string) (*Page[ModelVersion], error)
- func (r *Client) ListPredictions(ctx context.Context) (*Page[Prediction], error)
- func (r *Client) ListTrainings(ctx context.Context) (*Page[Training], error)
- func (r *Client) Run(ctx context.Context, identifier string, input PredictionInput, ...) (PredictionOutput, error)
- func (r *Client) Wait(ctx context.Context, prediction *Prediction, opts ...WaitOption) error
- func (r *Client) WaitAsync(ctx context.Context, prediction *Prediction, opts ...WaitOption) (<-chan *Prediction, <-chan error)
- type ClientOption
- type Collection
- type ConstantBackoff
- type ExponentialBackoff
- type Model
- type ModelVersion
- type Page
- type Prediction
- type PredictionInput
- type PredictionOutput
- type PredictionProgress
- type Source
- type Status
- type Training
- type TrainingInput
- type WaitOption
- type Webhook
- type WebhookEventType
Constants ¶
This section is empty.
Variables ¶
var (
ErrNoAuth = errors.New(`no auth token or token source provided -- perhaps you forgot to pass replicate.WithToken("...")`)
)
var WebhookEventAll = []WebhookEventType{ WebhookEventStart, WebhookEventOutput, WebhookEventLogs, WebhookEventCompleted, }
Functions ¶
Types ¶
type APIError ¶
type APIError struct {
Detail string `json:"detail"`
}
APIError represents an error returned by the Replicate API
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a client for the Replicate API.
func NewClient ¶
func NewClient(opts ...ClientOption) (*Client, error)
NewClient creates a new Replicate API client.
func (*Client) CancelTraining ¶
CancelTraining sends a request to the Replicate API to cancel a training.
func (*Client) CreatePrediction ¶
func (r *Client) CreatePrediction(ctx context.Context, version string, input PredictionInput, webhook *Webhook, stream bool) (*Prediction, error)
CreatePrediction sends a request to the Replicate API to create a prediction.
func (*Client) CreateTraining ¶
func (r *Client) CreateTraining(ctx context.Context, model_owner string, model_name string, version string, destination string, input TrainingInput, webhook *Webhook) (*Training, error)
CreateTraining sends a request to the Replicate API to create a new training.
func (*Client) GetCollection ¶
GetCollection returns a collection by slug.
func (*Client) GetModelVersion ¶
func (r *Client) GetModelVersion(ctx context.Context, modelOwner string, modelName string, versionID string) (*ModelVersion, error)
GetModelVersion retrieves a specific version of a model.
func (*Client) GetPrediction ¶
GetPrediction retrieves a prediction from the Replicate API by its ID.
func (*Client) GetTraining ¶
GetTraining sends a request to the Replicate API to get a training.
func (*Client) ListCollections ¶
ListCollections returns a list of all collections.
func (*Client) ListModelVersions ¶
func (r *Client) ListModelVersions(ctx context.Context, modelOwner string, modelName string) (*Page[ModelVersion], error)
ListModelVersions lists the versions of a model.
func (*Client) ListPredictions ¶
ListPredictions returns a paginated list of predictions.
func (*Client) ListTrainings ¶
ListTrainings returns a list of trainings.
func (*Client) Run ¶
func (r *Client) Run(ctx context.Context, identifier string, input PredictionInput, webhook *Webhook) (PredictionOutput, error)
func (*Client) Wait ¶
func (r *Client) Wait(ctx context.Context, prediction *Prediction, opts ...WaitOption) error
Wait for a prediction to finish.
This function blocks until the prediction has finished, or the context is cancelled. If the prediction has already finished, the function returns immediately. If polling interval is less than or equal to zero, an error is returned.
func (*Client) WaitAsync ¶ added in v0.7.0
func (r *Client) WaitAsync(ctx context.Context, prediction *Prediction, opts ...WaitOption) (<-chan *Prediction, <-chan error)
WaitAsync returns a channel that receives the prediction as it progresses.
The channel is closed when the prediction has finished, or the context is cancelled. If the prediction has already finished, the channel is closed immediately. If polling interval is less than or equal to zero, an error is sent to the error channel.
type ClientOption ¶
type ClientOption func(*clientOptions) error
ClientOption is a function that modifies an options struct.
func WithBaseURL ¶
func WithBaseURL(baseURL string) ClientOption
WithBaseURL sets the base URL for the client.
func WithHTTPClient ¶
func WithHTTPClient(httpClient *http.Client) ClientOption
WithHTTPClient sets the HTTP client used by the client.
func WithRetryPolicy ¶ added in v0.7.0
func WithRetryPolicy(maxRetries int, backoff Backoff) ClientOption
WithRetryPolicy sets the retry policy used by the client.
func WithToken ¶ added in v0.6.0
func WithToken(token string) ClientOption
WithToken sets the auth token used by the client.
func WithTokenFromEnv ¶ added in v0.6.0
func WithTokenFromEnv() ClientOption
WithTokenFromEnv configures the client to use the auth token provided in the REPLICATE_API_TOKEN environment variable.
func WithUserAgent ¶
func WithUserAgent(userAgent string) ClientOption
WithUserAgent sets the User-Agent header on requests made by the client.
type Collection ¶
type ConstantBackoff ¶ added in v0.7.0
ConstantBackoff is a backoff strategy that returns a constant delay with some jitter.
type ExponentialBackoff ¶ added in v0.7.0
ExponentialBackoff is a backoff strategy that returns an exponentially increasing delay with some jitter.
type Model ¶
type Model struct { URL string `json:"url"` Owner string `json:"owner"` Name string `json:"name"` Description string `json:"description"` Visibility string `json:"visibility"` GithubURL string `json:"github_url"` PaperURL string `json:"paper_url"` LicenseURL string `json:"license_url"` RunCount int `json:"run_count"` CoverImageURL string `json:"cover_image_url"` DefaultExample *Prediction `json:"default_example"` LatestVersion *ModelVersion `json:"latest_version"` }
type ModelVersion ¶
type Page ¶
type Page[T any] struct { Previous *string `json:"previous,omitempty"` Next *string `json:"next,omitempty"` Results []T `json:"results"` }
Page represents a paginated response from Replicate's API.
type Prediction ¶
type Prediction struct { ID string `json:"id"` Status Status `json:"status"` Version string `json:"version"` Input PredictionInput `json:"input"` Output PredictionOutput `json:"output,omitempty"` Source Source `json:"source"` Error interface{} `json:"error,omitempty"` Logs *string `json:"logs,omitempty"` Metrics *struct { PredictTime *float64 `json:"predict_time,omitempty"` } `json:"metrics,omitempty"` Webhook *string `json:"webhook,omitempty"` WebhookEventsFilter []WebhookEventType `json:"webhook_events_filter,omitempty"` URLs map[string]string `json:"urls,omitempty"` CreatedAt string `json:"created_at"` StartedAt *string `json:"started_at,omitempty"` CompletedAt *string `json:"completed_at,omitempty"` }
func (Prediction) Progress ¶ added in v0.8.0
func (p Prediction) Progress() *PredictionProgress
type PredictionInput ¶
type PredictionInput map[string]interface{}
type PredictionOutput ¶
type PredictionOutput interface{}
type PredictionProgress ¶ added in v0.8.0
type Training ¶
type Training Prediction
type TrainingInput ¶
type TrainingInput PredictionInput
type WaitOption ¶ added in v0.7.0
type WaitOption func(*waitOptions) error
WaitOption is a function that modifies an options struct.
func WithPollingInterval ¶ added in v0.7.0
func WithPollingInterval(interval time.Duration) WaitOption
WithPollingInterval sets the interval between attempts.
type Webhook ¶
type Webhook struct { URL string Events []WebhookEventType }
type WebhookEventType ¶
type WebhookEventType string
const ( WebhookEventStart WebhookEventType = "start" WebhookEventOutput WebhookEventType = "output" WebhookEventLogs WebhookEventType = "logs" WebhookEventCompleted WebhookEventType = "completed" )
func (WebhookEventType) String ¶
func (w WebhookEventType) String() string