@runware/sdk-js 1.0.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +251 -0
- package/dist/index.d.ts +251 -0
- package/dist/index.js +1314 -0
- package/dist/index.mjs +1293 -0
- package/package.json +44 -0
- package/readme.md +336 -0
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@runware/sdk-js",
|
|
3
|
+
"version": "1.0.27",
|
|
4
|
+
"description": "The SDK is used to run image inference with the Runware API, powered by the RunWare inference platform. It can be used to generate imaged with text-to-image and image-to-image. It also allows the use of an existing gallery of models or selecting any model or LoRA from the CivitAI gallery. The API also supports upscaling, background removal, inpainting and outpainting, and a series of other ControlNet models.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist/"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "tsup Runware/index.ts --format cjs,esm --dts",
|
|
13
|
+
"lint": "tsc",
|
|
14
|
+
"pkg": "npx pkgfiles",
|
|
15
|
+
"dev:test": "vitest --reporter verbose",
|
|
16
|
+
"test": "vitest run --reporter verbose",
|
|
17
|
+
"test:single": "vitest run --reporter verbose tests/Runware/request-images.test.ts"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"runware",
|
|
21
|
+
"sdk",
|
|
22
|
+
"ai"
|
|
23
|
+
],
|
|
24
|
+
"author": "",
|
|
25
|
+
"license": "ISC",
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/uuid": "^9.0.6",
|
|
28
|
+
"@types/ws": "^8.5.8",
|
|
29
|
+
"mock-socket": "^9.3.1",
|
|
30
|
+
"tsup": "^7.2.0",
|
|
31
|
+
"typescript": "^5.2.2",
|
|
32
|
+
"vitest": "^0.34.6"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"uuid": "^9.0.1",
|
|
36
|
+
"ws": "^8.14.2"
|
|
37
|
+
},
|
|
38
|
+
"optionalDependencies": {
|
|
39
|
+
"bufferutil": "^4.0.8"
|
|
40
|
+
},
|
|
41
|
+
"directories": {
|
|
42
|
+
"test": "tests"
|
|
43
|
+
}
|
|
44
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
# Runware Javascript & Typescript SDK
|
|
2
|
+
|
|
3
|
+
> This SDK is used to run AI image generation with the Runware API, powered by the RunWare inference platform. With this SDK you can generate images with text-to-image and image-to-image with sub-second inference times. It also allows the use of an existing library of more than 150k models, including any model or LoRA from the CivitAI gallery. The API also supports upscaling, background removal, inpainting, outpainting, ControlNets, and more. Visit the Runware site for [detailed feature breakdown](https://runware.ai/features/).
|
|
4
|
+
|
|
5
|
+
## Get API access
|
|
6
|
+
|
|
7
|
+
For an API Key and free trial credits, [create a free account](https://my.runware.ai/) with [Runware](https://runware.ai)
|
|
8
|
+
|
|
9
|
+
### NB: Please keep your API key private
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
To install and set up the library, run:
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
$ npm install runware-sdk
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Or if you prefer using Yarn:
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
$ yarn add runware-sdk
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Instantiating the SDK
|
|
26
|
+
|
|
27
|
+
```js
|
|
28
|
+
# For Client (Javascript, React, Vue etc) Use
|
|
29
|
+
const runware = new Runware({ apiKey: "API_KEY" });
|
|
30
|
+
|
|
31
|
+
# For Server (Nodejs) Use
|
|
32
|
+
const runware = new RunwareServer({ apiKey: "API_KEY" });
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
| Parameter | Type | Use |
|
|
36
|
+
| --------- | ------ | --------------------------------- |
|
|
37
|
+
| url | string | Url to get images from (optional) |
|
|
38
|
+
| apiKey | string | The environment api key |
|
|
39
|
+
|
|
40
|
+
## API
|
|
41
|
+
|
|
42
|
+
### Request Image
|
|
43
|
+
|
|
44
|
+
NB: All errors can be caught in the catch block of each request
|
|
45
|
+
|
|
46
|
+
```js
|
|
47
|
+
const runware = new Runware({ apiKey: "API_KEY" });
|
|
48
|
+
const images = await runware.requestImages({
|
|
49
|
+
positivePrompt: string;
|
|
50
|
+
imageSize: number;
|
|
51
|
+
modelId: number;
|
|
52
|
+
numberOfImages?: number;
|
|
53
|
+
negativePrompt?: string;
|
|
54
|
+
useCache?: boolean;
|
|
55
|
+
lora?: ILora[];
|
|
56
|
+
controlNet?: IControlNet[];
|
|
57
|
+
imageInitiator?: File | string;
|
|
58
|
+
imageMaskInitiator?: File | string;
|
|
59
|
+
steps?: number;
|
|
60
|
+
onPartialImages?: (images: IImage[], error: IError) => void;
|
|
61
|
+
})
|
|
62
|
+
console.log(images)
|
|
63
|
+
|
|
64
|
+
return interface IImage {
|
|
65
|
+
imageSrc: string;
|
|
66
|
+
imageUUID: string;
|
|
67
|
+
taskUUID: string;
|
|
68
|
+
bNSFWContent: boolean;
|
|
69
|
+
}[]
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
##### Parallel Requests (2 or more requests at the same time)
|
|
73
|
+
|
|
74
|
+
```js
|
|
75
|
+
const runware = new Runware({ apiKey: "API_KEY" });
|
|
76
|
+
|
|
77
|
+
const [firstImagesRequest, secondImagesRequest] = await Promise.all([
|
|
78
|
+
runware.requestImages({
|
|
79
|
+
positivePrompt: string;
|
|
80
|
+
imageSize: number;
|
|
81
|
+
modelId: number;
|
|
82
|
+
numberOfImages?: number;
|
|
83
|
+
negativePrompt?: string;
|
|
84
|
+
useCache?: boolean;
|
|
85
|
+
onPartialImages?: (images: IImage[], error: IError) => void;
|
|
86
|
+
}),
|
|
87
|
+
runware.requestImages({
|
|
88
|
+
positivePrompt: string;
|
|
89
|
+
imageSize: number;
|
|
90
|
+
modelId: number;
|
|
91
|
+
numberOfImages?: number;
|
|
92
|
+
negativePrompt?: string;
|
|
93
|
+
useCache?: boolean;
|
|
94
|
+
onPartialImages?: (images: IImage[], error: IError) => void;
|
|
95
|
+
})
|
|
96
|
+
])
|
|
97
|
+
|
|
98
|
+
console.log({firstImagesRequest, secondImagesRequest})
|
|
99
|
+
|
|
100
|
+
return interface IImage {
|
|
101
|
+
imageSrc: string;
|
|
102
|
+
imageUUID: string;
|
|
103
|
+
taskUUID: string;
|
|
104
|
+
bNSFWContent: boolean;
|
|
105
|
+
}[]
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
| Parameter | Type | Use |
|
|
109
|
+
| ------------------ | ---------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
110
|
+
| positivePrompt | string | Defines the positive prompt description of the image. |
|
|
111
|
+
| imageSize | number | Controls the image size. |
|
|
112
|
+
| modelId | number | The model id of the image to be requested. |
|
|
113
|
+
| numberOfImages | number: `(Optional)` (default = 1) | `(Optional)` The number of images to be sent. |
|
|
114
|
+
| useCache | string: `(Optional)` | Should use cached images (for faster response) or generate new images. |
|
|
115
|
+
| lora | ILora[]: `(Optional)` | If provided it should be an array of objects. Each object must have two attributes: `loraCivitaiAIR` (string) and `weight` (float) with values from 0 to 1. |
|
|
116
|
+
| controlNet | IControlNet[]: `(Optional)` | If provided, should be an array of objects. Each object must have five attributes: |
|
|
117
|
+
| imageInitiator | string or File: `(Optional)` | The image to be used as the seed image. It can be the UUID of previously generated image, or an image from a file. |
|
|
118
|
+
| imageMaskInitiator | string or File: `(Optional)` | The image to be used as the mask image. It can be the UUID of previously generated image, or an image from a file. |
|
|
119
|
+
| steps | number: `(Optional)` | The steps required to generate the image. |
|
|
120
|
+
| onPartialImages | function: `(Optional)` | If you want to receive the images as they are generated instead of waiting for the async request, you get the images as they are generated from this function. |
|
|
121
|
+
|
|
122
|
+
##### ControlNet Params
|
|
123
|
+
|
|
124
|
+
| Parameter | Type | Use |
|
|
125
|
+
| --------------------- | ---------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
126
|
+
| preprocessor | string | Defines the positive prompt description of the image. |
|
|
127
|
+
| weight | number | an have values between 0 and 1 and represent the weight of the ControlNet preprocessor in the image. |
|
|
128
|
+
| startStep | number | represents the moment in which the ControlNet preprocessor starts to control the inference. It can take values from 0 to the maximum number of `steps` in the image create request. This can also be replaced with `startStepPercentage` (float) which represents the same value but in percentages. It takes values from 0 to 1. |
|
|
129
|
+
| numberOfImages | number: `(Optional)` (default = 1) | `(Optional)` The number of images to be sent. |
|
|
130
|
+
| endStep | number | similar with `startStep` but represents the end of the preprocessor control of the image inference. The equivalent of the percentage option is `startStepPercentage` (float). |
|
|
131
|
+
| guideImage | file or string `(Optional)` | The image requires for the guide image. It can be the UUID of previously generated image, or an image from a file. |
|
|
132
|
+
| guideImageUnprocessed | file or string `(Optional)` | The image requires for the guide image unprocessed. It can be the UUID of previously generated image, or an image from a file. |
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
### Request Image To Text
|
|
137
|
+
|
|
138
|
+
```js
|
|
139
|
+
|
|
140
|
+
const runware = new Runware({ apiKey: "API_KEY" });
|
|
141
|
+
const imageToText = await runware.requestImageToText({
|
|
142
|
+
imageInitiator: string | File
|
|
143
|
+
})
|
|
144
|
+
console.log(imageToText)
|
|
145
|
+
|
|
146
|
+
return interface IImageToText {
|
|
147
|
+
taskUUID: string;
|
|
148
|
+
text: string;
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
| Parameter | Type | Use |
|
|
153
|
+
| -------------- | -------------- | ------------------------------------------------------------------------------------------------------------------ |
|
|
154
|
+
| imageInitiator | string or File | The image to be used as the seed image. It can be the UUID of previously generated image, or an image from a file. |
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
### Remove Image Background
|
|
159
|
+
|
|
160
|
+
```js
|
|
161
|
+
|
|
162
|
+
const runware = new Runware({ apiKey: "API_KEY" });
|
|
163
|
+
const image = await runware.removeImageBackground({
|
|
164
|
+
imageInitiator: string | File
|
|
165
|
+
})
|
|
166
|
+
console.log(image)
|
|
167
|
+
return interface IImage {
|
|
168
|
+
imageSrc: string;
|
|
169
|
+
imageUUID: string;
|
|
170
|
+
taskUUID: string;
|
|
171
|
+
bNSFWContent: boolean;
|
|
172
|
+
}[]
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
| Parameter | Type | Use |
|
|
176
|
+
| -------------- | -------------- | ------------------------------------------------------------------------------------------------------------------ |
|
|
177
|
+
| imageInitiator | string or File | The image to be used as the seed image. It can be the UUID of previously generated image, or an image from a file. |
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
### Upscale Image
|
|
182
|
+
|
|
183
|
+
```js
|
|
184
|
+
|
|
185
|
+
const runware = new Runware({ apiKey: "API_KEY" });
|
|
186
|
+
const image = await runware.upscaleGan({
|
|
187
|
+
imageInitiator: string | File;
|
|
188
|
+
upscaleFactor: number;
|
|
189
|
+
})
|
|
190
|
+
console.log(image)
|
|
191
|
+
return interface IImage {
|
|
192
|
+
imageSrc: string;
|
|
193
|
+
imageUUID: string;
|
|
194
|
+
taskUUID: string;
|
|
195
|
+
bNSFWContent: boolean;
|
|
196
|
+
}[]
|
|
197
|
+
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
| Parameter | Type | Use |
|
|
201
|
+
| -------------- | -------------- | ------------------------------------------------------------------------------------------------------------------ |
|
|
202
|
+
| imageInitiator | string or File | The image to be used as the seed image. It can be the UUID of previously generated image, or an image from a file. |
|
|
203
|
+
| upscaleFactor | number | The number of times to upscale; |
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
### Enhance Prompt
|
|
208
|
+
|
|
209
|
+
```js
|
|
210
|
+
|
|
211
|
+
const runware = new Runware({ apiKey: "API_KEY" });
|
|
212
|
+
const enhancedPrompt = await runware.enhancePrompt({
|
|
213
|
+
prompt: string;
|
|
214
|
+
promptMaxLength?: number;
|
|
215
|
+
promptLanguageId?: number;
|
|
216
|
+
promptVersions?: number;
|
|
217
|
+
})
|
|
218
|
+
console.log(enhancedPrompt)
|
|
219
|
+
return interface IEnhancedPrompt {
|
|
220
|
+
taskUUID: string;
|
|
221
|
+
text: string;
|
|
222
|
+
}[]
|
|
223
|
+
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
| Parameter | Type | Use |
|
|
227
|
+
| ---------------- | ------------------ | --------------------------------------------------------------------------------------------------------------------------- |
|
|
228
|
+
| prompt | string | The prompt that you intend to enhance. |
|
|
229
|
+
| promptMaxLength | number: `Optional` | Character count. Represents the maximum length of the prompt that you intend to receive. Can take values between 1 and 380. |
|
|
230
|
+
| promptVersions | number: `Optional` | The number of prompt versions that will be received. Can take values between 1 and 5. |
|
|
231
|
+
| promptLanguageId | number: `Optional` | The language prompt text. Can take values between 1 and 298. Default is `1` - English. Options are provided below. |
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
## Demo
|
|
236
|
+
|
|
237
|
+
<!-- To be changed to another example -->
|
|
238
|
+
|
|
239
|
+
[**Demo**](https://codesandbox.io/s/picfinder-api-implementation-9tf85s?file=/src/App.tsx).
|
|
240
|
+
|
|
241
|
+
## Changelog
|
|
242
|
+
|
|
243
|
+
### - v1.0.27
|
|
244
|
+
|
|
245
|
+
**Added or Changed**
|
|
246
|
+
|
|
247
|
+
- Refactor websocket listeners
|
|
248
|
+
- Allow users to make parallel requests
|
|
249
|
+
|
|
250
|
+
### - v1.0.26
|
|
251
|
+
|
|
252
|
+
**Added or Changed**
|
|
253
|
+
|
|
254
|
+
- Validate valid UUID as image initiator
|
|
255
|
+
|
|
256
|
+
### - v1.0.25
|
|
257
|
+
|
|
258
|
+
**Added or Changed**
|
|
259
|
+
|
|
260
|
+
- Add Buffer utils necessary for server ws
|
|
261
|
+
- Return images generated if timeout reached
|
|
262
|
+
- Added support for LoRA
|
|
263
|
+
- Added support for seed
|
|
264
|
+
|
|
265
|
+
### - v1.0.24
|
|
266
|
+
|
|
267
|
+
**Added or Changed**
|
|
268
|
+
|
|
269
|
+
- Introduce retry for missing images
|
|
270
|
+
- Increase Polling time
|
|
271
|
+
|
|
272
|
+
### - v1.0.23
|
|
273
|
+
|
|
274
|
+
**Added or Changed**
|
|
275
|
+
|
|
276
|
+
- Fixed Upscalegan to allow imageUUID
|
|
277
|
+
|
|
278
|
+
### - v1.0.22
|
|
279
|
+
|
|
280
|
+
**Added or Changed**
|
|
281
|
+
|
|
282
|
+
- Fixed bugs
|
|
283
|
+
|
|
284
|
+
### - v1.0.21
|
|
285
|
+
|
|
286
|
+
**Added or Changed**
|
|
287
|
+
|
|
288
|
+
- Add control mode to control net
|
|
289
|
+
|
|
290
|
+
### - v1.0.20
|
|
291
|
+
|
|
292
|
+
**Added or Changed**
|
|
293
|
+
|
|
294
|
+
- Ensure connection for non instantiated instance
|
|
295
|
+
|
|
296
|
+
### - v1.0.19
|
|
297
|
+
|
|
298
|
+
**Added or Changed**
|
|
299
|
+
|
|
300
|
+
- Allow server sdk to reconnect on connection loss
|
|
301
|
+
- Prevent duplicate message in server sdk
|
|
302
|
+
- Modify connected method
|
|
303
|
+
- Reduced polling interval
|
|
304
|
+
|
|
305
|
+
### - v1.0.18
|
|
306
|
+
|
|
307
|
+
**Added or Changed**
|
|
308
|
+
|
|
309
|
+
- Exposed `connected`` method
|
|
310
|
+
|
|
311
|
+
### - v1.0.17
|
|
312
|
+
|
|
313
|
+
**Added or Changed**
|
|
314
|
+
|
|
315
|
+
- Minor Fixes
|
|
316
|
+
|
|
317
|
+
### - v1.0.16
|
|
318
|
+
|
|
319
|
+
**Added or Changed**
|
|
320
|
+
|
|
321
|
+
- Added Release Notes
|
|
322
|
+
|
|
323
|
+
### - v1.0.15
|
|
324
|
+
|
|
325
|
+
**Added or Changed**
|
|
326
|
+
|
|
327
|
+
- Added Server implementation (Nodejs)
|
|
328
|
+
- Added Errors catching
|
|
329
|
+
|
|
330
|
+
## Contributing
|
|
331
|
+
|
|
332
|
+
## Credits
|
|
333
|
+
|
|
334
|
+
## Resources
|
|
335
|
+
|
|
336
|
+
[**API Docs**](https://docs.runware.ai/)
|