Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sausheong/goreplicate
This is a simple Go package for interacting with the Replicate (https://replicate.com) HTTP APIs. Replicate is an API service that allows developers to use machine learning models easily through calling APIs.
https://github.com/sausheong/goreplicate
Last synced: 3 months ago
JSON representation
This is a simple Go package for interacting with the Replicate (https://replicate.com) HTTP APIs. Replicate is an API service that allows developers to use machine learning models easily through calling APIs.
- Host: GitHub
- URL: https://github.com/sausheong/goreplicate
- Owner: sausheong
- License: mit
- Created: 2022-09-11T07:03:37.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-09-06T05:34:40.000Z (about 1 year ago)
- Last Synced: 2024-06-20T12:37:35.804Z (5 months ago)
- Language: Go
- Size: 6.84 KB
- Stars: 27
- Watchers: 4
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-replicate - goreplicate - Go package for interacting with the Replicate HTTP APIs. (Client libraries)
README
# Go Replicate
[![Go Reference](https://pkg.go.dev/badge/github.com/sausheong/goreplicate.svg)](https://pkg.go.dev/github.com/sausheong/goreplicate)
This is a simple Go package for interacting with the Replicate (https://replicate.com) HTTP APIs. Replicate is an API service that allows developers to use machine learning models easily through calling APIs.
This package is based on the HTTP APIs -- https://replicate.com/docs/reference/http. Please read the APIs to understand how it works first.
## How to use
First, create a model. Go to https://replicate.com/explore to find the model you want to use. Then set up the input parameters for the model.
````go
model := NewModel("stability-ai", "stable-diffusion", version)
model.Input["prompt"] = "An astronaut riding a horse in photorealistic style"
model.Input["num_outputs"] = 4
````Then create a client, passing into it the API authentication token (you can get it here once you registered an account -- https://replicate.com/account) and the model you just created.
Using the client you can send a create prediction call to the API to start the prediction.
````go
client := NewClient(auth, model)
err := client.Create()
if err != nil {
// resolve the error here
}
````The client should have a `Response`, with an ID after calling the `Create` function. This is the prediction ID that you can use to retrieve the results of the prediction. At this point in time, the `Response` struct will have nothing in the `Output`
To get the results of the prediction, you can use the same client, or you can create a new client and call the `Get` function. This will return you the results of the prediction in the `Output`.
````go
err := client.Get(predictId)
if err != nil {
// resolve the error here
}
````