A small Go module for interfacing with RunwayML. It currently supports the new Hosted Models functionality, modeled after the official Hosted Models JavaScript SDK.
go get -u github.com/brannondorsey/go-runway
Several examples live in the examples/
directory.
package main
import (
"fmt"
"math/rand"
"time"
runway "github.com/brannondorsey/go-runway"
)
func main() {
// Replace this with the URL of your hosted model (https://learn.runwayml.com/#/how-to/hosted-models)
url := "https://example-text-generator.hosted-models.runwayml.cloud/v1"
// Paste your secret token in here. Leave as empty string if the model is public.
token := ""
model, err := runway.NewHostedModel(url, token)
if err != nil {
panic(err)
}
rand.Seed(time.Now().UnixNano())
input := runway.JSONObject{
"prompt": "Four score and seven years ago",
"seed": rand.Intn(1000),
"max_characters": 512,
}
fmt.Println("Querying model...")
output, err := model.Query(input)
if err != nil {
panic(err)
}
fmt.Println(output["generated_text"])
}
The hosted-models
example is a standalone utility for interfacing with hosted models. You can download it from the releases page.
# Call the /v1/info endpoint of the hosted model
hosted-models --url https://my-example-model.hosted-models.runwayml.cloud --token XXXX info
# {
# "name": "generate_batch",
# "description": "Generate text conditioned on prompt",
# "inputs": [
# {
# "default": "",
# "description": null,
# "minLength": 0,
# "name": "prompt",
# "type": "text"
# },
# ...
# ],
# "outputs": [
# {
# "default": "",
# "description": null,
# "minLength": 0,
# "name": "generated_text",
# "type": "text"
# },
# ...
# ]
# }
hosted-models --url https://my-example-model.hosted-models.runwayml.cloud --token XXXX \
query '{"prompt": "Four score and seven years ago"}'
# {
# "encountered_end": false,
# "generated_text": "Four score and seven years ago the sorcerer Anor stood before the king, as a new wizard of the"
# }
The Go docs for this package live here on go.dev.
See the Usage section of the Hosted Models JavaScript SDK for general information about the methods available for the HostedModel
object, as they are identical to the ones provided by this package.
Running make
will build all examples/
and place their executables in build/bin
.
git clone https://github.com/brannondorsey/go-runway
cd runway
make