├── .circleci
└── config.yml
├── .eslintrc
├── .gitignore
├── .npmignore
├── .prettierrc
├── .vscode
├── extensions.json
└── settings.json
├── CHANGELOG.md
├── LICENSE
├── README.md
├── docs
├── assets
│ ├── css
│ │ └── main.css
│ ├── images
│ │ ├── icons.png
│ │ ├── icons@2x.png
│ │ ├── widgets.png
│ │ └── widgets@2x.png
│ └── js
│ │ ├── main.js
│ │ └── search.json
├── classes
│ ├── _hostedmodel_.hostedmodel.html
│ ├── _httperrors_.invalidargumenterror.html
│ ├── _httperrors_.invlaidurlerror.html
│ ├── _httperrors_.modelerror.html
│ ├── _httperrors_.networkerror.html
│ ├── _httperrors_.notfounderror.html
│ ├── _httperrors_.permissiondeniederror.html
│ └── _httperrors_.unexpectederror.html
├── globals.html
├── index.html
├── interfaces
│ └── _hostedmodel_.hostedmodelconfig.html
└── modules
│ ├── _hostedmodel_.html
│ └── _httperrors_.html
├── examples
├── browser.html
├── node.js
└── ts-node.ts
├── package-lock.json
├── package.json
├── secrets.txt
├── src
├── HTTPErrors.ts
├── HostedModel.ts
├── index.ts
└── utils.ts
└── tsconfig.json
/.circleci/config.yml:
--------------------------------------------------------------------------------
1 | version: 2.1
2 | jobs:
3 | publish:
4 | docker:
5 | - image: circleci/node:12
6 | steps:
7 | - checkout
8 | - run: sudo apt-get install jq
9 | - restore_cache:
10 | key: dependency-cache-{{ checksum "package-lock.json" }}
11 | - run: npm install
12 | - run:
13 | name: Download awssecret2env
14 | command: |
15 | wget https://awssecret2env.s3.amazonaws.com/latest/awssecret2env-linux64
16 | chmod +x awssecret2env-linux64 && mv awssecret2env-linux64 awssecret2env
17 | - run:
18 | name: Add .env
19 | command: ./awssecret2env --export --output .env secrets.txt
20 | - run:
21 | name: Publish If New Version
22 | command: |
23 | NPM_VERSION=$(npm view @runwayml/hosted-models versions --json | jq -r '.[-1]')
24 | LOCAL_VERSION=$(jq -r .version package.json)
25 | if [[ "$NPM_VERSION" != "$LOCAL_VERSION" ]]; then
26 | source .env
27 | echo "Local version $LOCAL_VERSION doesn't match npm version $NPM_VERSION"
28 | echo "Publishing a new release!"
29 | echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > .npmrc
30 | npm publish --access public
31 | else
32 | echo "Local version $LOCAL_VERSION matches npm version $NPM_VERSION"
33 | echo "Not publishing a new release."
34 | fi
35 | - save_cache:
36 | paths:
37 | - node_modules
38 | key: dependency-cache-{{ checksum "package-lock.json" }}
39 | workflows:
40 | version: 2
41 | publish:
42 | jobs:
43 | - publish:
44 | filters:
45 | branches:
46 | only: master
47 |
--------------------------------------------------------------------------------
/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "ignorePatterns": ["node_modules/"],
3 | "parserOptions": {
4 | "sourceType": "module"
5 | },
6 | "env": {
7 | "node": true,
8 | "es6": true
9 | },
10 | "extends": [
11 | "eslint:recommended",
12 | "plugin:@typescript-eslint/eslint-recommended",
13 | "plugin:@typescript-eslint/recommended",
14 | // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier.
15 | "prettier/@typescript-eslint",
16 | // Enables eslint-plugin-prettier and eslint-config-prettier.
17 | // This will display prettier errors as ESLint errors.
18 | // Make sure this is always the last configuration in the extends array.
19 | "plugin:prettier/recommended"
20 | ],
21 | "plugins": ["@typescript-eslint", "prettier", "simple-import-sort"],
22 | "rules": {
23 | "simple-import-sort/sort": "error",
24 | "no-empty": "off",
25 | "no-case-declarations": "off",
26 | "no-prototype-builtins": "off",
27 | "no-constant-condition": "off",
28 | "@typescript-eslint/explicit-function-return-type": "off",
29 | "@typescript-eslint/ban-ts-ignore": "off",
30 | "@typescript-eslint/no-explicit-any": "off",
31 | "@typescript-eslint/camelcase": "off",
32 | "@typescript-eslint/no-use-before-define": "off",
33 | "@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "_" }]
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules/
3 | build/
4 | dist/
5 | .eslintcache
6 | .cache/
7 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | .vscode/
2 | .cache/
3 | .eslintcache
4 | secrets.txt
5 |
--------------------------------------------------------------------------------
/.prettierrc:
--------------------------------------------------------------------------------
1 | {
2 | "trailingComma": "es5",
3 | "singleQuote": true,
4 | "semi": true,
5 | "endOfLine": "lf",
6 | "arrowParens": "avoid"
7 | }
8 |
--------------------------------------------------------------------------------
/.vscode/extensions.json:
--------------------------------------------------------------------------------
1 | {
2 | "recommendations": ["esbenp.prettier-vscode"]
3 | }
4 |
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "editor.defaultFormatter": "esbenp.prettier-vscode",
3 | "[javascript]": {
4 | "editor.defaultFormatter": "esbenp.prettier-vscode"
5 | },
6 | "[typescript]": {
7 | "editor.defaultFormatter": "esbenp.prettier-vscode"
8 | },
9 | "editor.formatOnSave": true,
10 | "eslint.format.enable": true,
11 | "editor.codeActionsOnSave": {
12 | "source.fixAll.eslint": true
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 | ## v0.3.0
4 |
5 | - Add usage section in README.
6 | - More descriptive error message for `NotFoundError`.
7 | - Wake up model during `HostedModel` construction.
8 | - Add optional `pollIntervalMillis` parameter to `HostedModel.waitUntilAwake()` method.
9 |
10 | ## v0.2.0
11 |
12 | - Add CI/CD releases via CircleCI
13 | - Fix infinite loop with `npm run build`.
14 | - Add inline documentation with TypeDoc, generated in `docs/`.
15 | - Add `InvalidArgumentError` type and throw it when invalid arguments are passed to public methods.
16 |
17 | ## v0.1.0
18 |
19 | Initial release.
20 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 Runway
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Hosted Models JavaScript SDK
2 |
3 | [](https://runwayml.com)
4 |
5 | A small library for interfacing with RunwayML [Hosted Models](https://learn.runwayml.com/#/how-to/hosted-models) using only a few lines of code. Works in both Node.js and the Browser.
6 |
7 | ## Benefits
8 |
9 | This library is a thin wrapper around the Hosted Models [HTTP API](https://learn.runwayml.com/#/how-to/hosted-models?id=http-api). It provides a few benefits:
10 |
11 | - Abstracts the HTTP requests to the Hosted Model, so you don't have to make them directly.
12 | - Simplifies authorization for private models, just provide your `token` in the `new HostedModels({ url, token })` constructor.
13 | - Automatically retries failed requests if they timed out while the model wakes up or are blocked due to rate-limiting.
14 | - Includes friendly error reporting with messages for humans, so you can better understand why something went wrong.
15 |
16 | If your project is written in JavaScript, we encourage you to use this library!
17 |
18 | ## Examples
19 |
20 | See the [`examples/`](examples) directory for a full list of examples.
21 |
22 | ### Node.js / Module Syntax
23 |
24 | If you are using Node.js or packaging your front-end code via a bundler, you can install the module using `npm`.
25 |
26 | ```bash
27 | npm install --save @runwayml/hosted-models
28 | ```
29 |
30 | ```javascript
31 | const { HostedModel } = require('@runwayml/hosted-models');
32 |
33 | const model = new HostedModel({
34 | url: 'https://my-model.hosted-models.runwayml.cloud/v1',
35 | token: 'my-private-hosted-model-token',
36 | });
37 |
38 | const prompt = 'Hey text generation model, finish my sentence';
39 | model.query({ prompt }).then(result => console.log(result));
40 | ```
41 |
42 | ### Browser
43 |
44 | If you prefer to access the library in the Browser using a `
48 | ```
49 |
50 | This injects the library into the window and exposes it via the `rw` namespace.
51 |
52 | ```javascript
53 | const model = new rw.HostedModel({
54 | url: 'https://my-model.hosted-models.runwayml.cloud/v1',
55 | token: 'my-private-hosted-model-token',
56 | });
57 |
58 | const prompt = 'Hey text generation model, finish my sentence';
59 | model.query({ prompt }).then(result => console.log(result));
60 | ```
61 |
62 | ## Usage
63 |
64 | This library is super simple to use; It exposes a single `HostedModels` class with only four methods:
65 |
66 | - [`HostedModel`](#hostedmodels-constructor)
67 | - [`.info()`](#info-method)
68 | - [`.query()`](#query-method)
69 | - [`.isAwake()`](#isAwake-method)
70 | - [`.waitUntilAwake()`](#waitUntilAwake-method)
71 |
72 | > Note: Be sure to use `rw.HostedModel()` if you are including the library via a `
533 |
534 |