https://github.com/brannondorsey/go-runway
A small Go module for interfacing with RunwayML
https://github.com/brannondorsey/go-runway
golang golang-library machine-learning runway runwayml
Last synced: 5 months ago
JSON representation
A small Go module for interfacing with RunwayML
- Host: GitHub
- URL: https://github.com/brannondorsey/go-runway
- Owner: brannondorsey
- License: mit
- Created: 2020-05-05T02:47:17.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-05-16T23:24:49.000Z (over 5 years ago)
- Last Synced: 2024-06-20T16:45:07.401Z (over 1 year ago)
- Topics: golang, golang-library, machine-learning, runway, runwayml
- Language: Go
- Size: 53.7 KB
- Stars: 7
- Watchers: 3
- Forks: 3
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# RunwayML Go
A small Go module for interfacing with RunwayML. It currently supports the new [Hosted Models](https://learn.runwayml.com/#/how-to/hosted-models) functionality, modeled after the official [Hosted Models JavaScript SDK](https://github.com/runwayml/hosted-models/).
```bash
go get -u github.com/brannondorsey/go-runway
```## Examples
Several examples live in the `examples/` directory.
### Basic
```go
package mainimport (
"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
The [`hosted-models` example](examples/hosted-models/main.go) is a standalone utility for interfacing with hosted models. You can download it from the [releases page](https://github.com/brannondorsey/go-runway/releases).
```bash
# 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"
# },
# ...
# ]
# }
``````bash
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"
# }
```## Docs
The Go docs for this package live [here on go.dev](https://pkg.go.dev/github.com/brannondorsey/go-runway?tab=doc).
See the [Usage](https://github.com/runwayml/hosted-models/) 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.
## Dev
Running `make` will build all `examples/` and place their executables in `build/bin`.
```bash
git clone https://github.com/brannondorsey/go-runway
cd runwaymake
```