runpod-sdk 1.0.3 → 1.0.5
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/README.md +60 -3
- package/dist/index.d.ts +22 -13
- package/dist/index.js +142 -67
- package/dist/index.js.map +1 -0
- package/examples/basic.js +19 -0
- package/examples/cancel.js +27 -0
- package/examples/devServerless.js +17 -0
- package/examples/errors.js +11 -0
- package/examples/health.js +11 -0
- package/examples/purge-queue.js +11 -0
- package/examples/run.js +27 -0
- package/examples/runSync.js +17 -0
- package/examples/stream.js +48 -0
- package/examples/test.js +46 -13
- package/package.json +1 -1
- package/src/index.ts +132 -53
- package/tsconfig.json +2 -1
- package/examples/example.js +0 -17
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ const result = await endpoint.runSync({
|
|
|
22
22
|
Once an endpoint has been created, you can send requests to the queue:
|
|
23
23
|
|
|
24
24
|
```js
|
|
25
|
-
const
|
|
25
|
+
const { id } = await endpoint.run({
|
|
26
26
|
input: {
|
|
27
27
|
prompt: "a photo of a horse the size of a Boeing 787",
|
|
28
28
|
},
|
|
@@ -32,7 +32,7 @@ const requestId = await endpoint.run({
|
|
|
32
32
|
You can check on the status of this request once you have the id:
|
|
33
33
|
|
|
34
34
|
```js
|
|
35
|
-
const status = await endpoint.
|
|
35
|
+
const status = await endpoint.status(id);
|
|
36
36
|
```
|
|
37
37
|
|
|
38
38
|
If the request has been completed, the status object returned will contain the `output` of the request.
|
|
@@ -56,5 +56,62 @@ await endpoint.cancel(requestId);
|
|
|
56
56
|
For long running applications or troubleshooting, you may want to check the health of the endpoint workers:
|
|
57
57
|
|
|
58
58
|
```js
|
|
59
|
-
const health = await endpoint.
|
|
59
|
+
const health = await endpoint.health();
|
|
60
60
|
```
|
|
61
|
+
|
|
62
|
+
Some Runpod endpoints are configured to yield multiple results for a single input, which can be streamed locally:
|
|
63
|
+
|
|
64
|
+
```js
|
|
65
|
+
const { id } = await endpoint.run({
|
|
66
|
+
input: {
|
|
67
|
+
prompt: "7 photos of a horse the size of a Boeing 787",
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
for await (const result of endpoint.stream(id)) {
|
|
72
|
+
console.log("Stream yielded another photo:");
|
|
73
|
+
console.log(result.output);
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
(this horse photo endpoint is fictitious, but it shows why you might want a stream of results)
|
|
78
|
+
|
|
79
|
+
# Timeouts
|
|
80
|
+
|
|
81
|
+
All endpoint functions have a `timeout` parameter which is the maximum amount of time, in milliseconds, to wait for the function to complete.
|
|
82
|
+
|
|
83
|
+
For example,
|
|
84
|
+
|
|
85
|
+
```js
|
|
86
|
+
const result = await endpoint.runSync({
|
|
87
|
+
input: {
|
|
88
|
+
prompt: "a photo of a horse the size of a Boeing 787",
|
|
89
|
+
},
|
|
90
|
+
}, 5000);
|
|
91
|
+
```
|
|
92
|
+
will timeout after 5 seconds.
|
|
93
|
+
|
|
94
|
+
Note that this is the timeout on the *local* function call, not the underlying request in the queue. So this:
|
|
95
|
+
|
|
96
|
+
```js
|
|
97
|
+
const result = await endpoint.run({
|
|
98
|
+
input: {
|
|
99
|
+
prompt: "a photo of a horse the size of a Boeing 787",
|
|
100
|
+
},
|
|
101
|
+
}, 3000);
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
will not enqueue a request which can only take 3 seconds on the server, it will only timeout if the enqueue itself is slower than 3 seconds.
|
|
105
|
+
|
|
106
|
+
To affect the maximum time a request can take on the backend, you can provide a policy in the request input:
|
|
107
|
+
|
|
108
|
+
```js
|
|
109
|
+
const result = await endpoint.run({
|
|
110
|
+
input: {
|
|
111
|
+
prompt: "a photo of a horse the size of a Boeing 787",
|
|
112
|
+
},
|
|
113
|
+
policy: {
|
|
114
|
+
executionTimeout: 3000,
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
```
|
package/dist/index.d.ts
CHANGED
|
@@ -11,10 +11,12 @@ export type S3Config = {
|
|
|
11
11
|
export type EndpointInputPayload = {
|
|
12
12
|
input: any;
|
|
13
13
|
webhook?: string;
|
|
14
|
+
webhookV2?: string;
|
|
14
15
|
s3Config?: S3Config;
|
|
15
16
|
policy?: ExecutionPolicy;
|
|
16
17
|
};
|
|
17
18
|
export type EndpointIncompleteOutput = {
|
|
19
|
+
delayTime?: number;
|
|
18
20
|
status: string;
|
|
19
21
|
id: string;
|
|
20
22
|
};
|
|
@@ -26,6 +28,10 @@ export type EndpointCompletedOutput = {
|
|
|
26
28
|
delayTime: number;
|
|
27
29
|
};
|
|
28
30
|
export type EndpointOutput = EndpointCompletedOutput | EndpointIncompleteOutput;
|
|
31
|
+
export type EndpointStreamOutput = {
|
|
32
|
+
status: string;
|
|
33
|
+
stream: [any];
|
|
34
|
+
};
|
|
29
35
|
export type CancelOutput = {
|
|
30
36
|
status: string;
|
|
31
37
|
id: string;
|
|
@@ -57,9 +63,10 @@ export type SdkOptions = {
|
|
|
57
63
|
};
|
|
58
64
|
export declare const runpodServerlessBaseUrlProd = "https://api.runpod.ai/v2";
|
|
59
65
|
export declare const runpodServerlessBaseUrlDev = "https://dev-api.runpod.ai/v2";
|
|
60
|
-
export declare const runSync: import("ts-toolbelt/out/Function/Curry").Curry<(baseUrl: string, apiKey: string, endpointId: string, request: EndpointInputPayload) => Promise<{
|
|
66
|
+
export declare const runSync: import("ts-toolbelt/out/Function/Curry").Curry<(baseUrl: string, apiKey: string, endpointId: string, request: EndpointInputPayload, timeout?: number) => Promise<{
|
|
61
67
|
started: boolean;
|
|
62
68
|
completed: boolean;
|
|
69
|
+
delayTime?: number | undefined;
|
|
63
70
|
status: string;
|
|
64
71
|
id: string;
|
|
65
72
|
} | {
|
|
@@ -74,6 +81,7 @@ export declare const runSync: import("ts-toolbelt/out/Function/Curry").Curry<(ba
|
|
|
74
81
|
started: boolean;
|
|
75
82
|
completed: boolean;
|
|
76
83
|
succeeded: boolean;
|
|
84
|
+
delayTime?: number | undefined;
|
|
77
85
|
status: string;
|
|
78
86
|
id: string;
|
|
79
87
|
} | {
|
|
@@ -86,23 +94,24 @@ export declare const runSync: import("ts-toolbelt/out/Function/Curry").Curry<(ba
|
|
|
86
94
|
executionTime: number;
|
|
87
95
|
delayTime: number;
|
|
88
96
|
}>>;
|
|
89
|
-
export declare const run: import("ts-toolbelt/out/Function/Curry").Curry<(baseUrl: string, apiKey: string, endpointId: string, request: EndpointInputPayload) => Promise<any>>;
|
|
90
|
-
export declare const
|
|
91
|
-
export declare
|
|
92
|
-
export declare const
|
|
93
|
-
export declare const purgeQueue: import("ts-toolbelt/out/Function/Curry").Curry<(baseUrl: string, apiKey: string, endpointId: string) => Promise<any>>;
|
|
97
|
+
export declare const run: import("ts-toolbelt/out/Function/Curry").Curry<(baseUrl: string, apiKey: string, endpointId: string, request: EndpointInputPayload, timeout?: number) => Promise<any>>;
|
|
98
|
+
export declare const status: import("ts-toolbelt/out/Function/Curry").Curry<(baseUrl: string, apiKey: string, endpointId: string, requestId: string, timeout?: number) => Promise<any>>;
|
|
99
|
+
export declare function stream(baseUrl: string, apiKey: string, endpointId: string, requestId: string, timeout?: number): AsyncGenerator<any, void, unknown>;
|
|
100
|
+
export declare const health: import("ts-toolbelt/out/Function/Curry").Curry<(baseUrl: string, apiKey: string, endpointId: string, timeout?: number) => Promise<any>>;
|
|
101
|
+
export declare const purgeQueue: import("ts-toolbelt/out/Function/Curry").Curry<(baseUrl: string, apiKey: string, endpointId: string, timeout?: number) => Promise<any>>;
|
|
94
102
|
declare class Endpoint {
|
|
95
103
|
endpointId: string;
|
|
96
104
|
baseUrl: string;
|
|
97
105
|
private apiKey;
|
|
98
106
|
constructor(baseUrl: string, apiKey: string, endpointId: string);
|
|
99
|
-
runSync(request: EndpointInputPayload): Promise<EndpointCompletedOutput>;
|
|
100
|
-
run(request: EndpointInputPayload): Promise<string>;
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
107
|
+
runSync(request: EndpointInputPayload, timeout?: number): Promise<EndpointCompletedOutput>;
|
|
108
|
+
run(request: EndpointInputPayload, timeout?: number): Promise<string>;
|
|
109
|
+
status(requestId: string, timeout?: number): Promise<EndpointOutput>;
|
|
110
|
+
statusSync(requestId: string, timeout?: number): Promise<EndpointOutput>;
|
|
111
|
+
stream(requestId: string, timeout?: number): AsyncGenerator<any>;
|
|
112
|
+
cancel(requestId: string, timeout?: number): Promise<CancelOutput>;
|
|
113
|
+
health(timeout?: number): Promise<HealthCheck>;
|
|
114
|
+
purgeQueue(timeout?: number): Promise<PurgeQueueOutput>;
|
|
106
115
|
}
|
|
107
116
|
declare class RunpodSdk {
|
|
108
117
|
private apiKey;
|
package/dist/index.js
CHANGED
|
@@ -45,6 +45,18 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
45
45
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
46
|
}
|
|
47
47
|
};
|
|
48
|
+
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
|
49
|
+
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
50
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
51
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
52
|
+
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
53
|
+
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
|
|
54
|
+
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
55
|
+
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
56
|
+
function fulfill(value) { resume("next", value); }
|
|
57
|
+
function reject(value) { resume("throw", value); }
|
|
58
|
+
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
59
|
+
};
|
|
48
60
|
import axios from "axios";
|
|
49
61
|
import { curry, clamp, isNil } from "ramda";
|
|
50
62
|
var getAuthHeader = function (apiKey) { return ({
|
|
@@ -54,7 +66,6 @@ var getAuthHeader = function (apiKey) { return ({
|
|
|
54
66
|
},
|
|
55
67
|
}); };
|
|
56
68
|
var print = console.log;
|
|
57
|
-
var sleep = function (ms) { return new Promise(function (resolve) { return setTimeout(resolve, ms); }); };
|
|
58
69
|
var handleErrors = function (axiosRequest) { return __awaiter(void 0, void 0, void 0, function () {
|
|
59
70
|
var resp, status, statusText;
|
|
60
71
|
return __generator(this, function (_a) {
|
|
@@ -81,92 +92,143 @@ var handleErrorsStatus = function (axiosRequest) { return __awaiter(void 0, void
|
|
|
81
92
|
if (status !== 200) {
|
|
82
93
|
return [2 /*return*/, { status: status, statusText: statusText, started: false }];
|
|
83
94
|
}
|
|
84
|
-
return [2 /*return*/, __assign(__assign({}, resp.data), { started: true, completed:
|
|
95
|
+
return [2 /*return*/, __assign(__assign({}, resp.data), { started: true, completed: isCompleted(resp.data.status), succeeded: resp.data.status === "COMPLETED" })];
|
|
85
96
|
}
|
|
86
97
|
});
|
|
87
98
|
}); };
|
|
88
99
|
export var runpodServerlessBaseUrlProd = "https://api.runpod.ai/v2";
|
|
89
100
|
export var runpodServerlessBaseUrlDev = "https://dev-api.runpod.ai/v2";
|
|
90
101
|
var getEndpointUrl = curry(function (baseUrl, endpointId) { return "".concat(baseUrl, "/").concat(endpointId); });
|
|
102
|
+
var isCompleted = function (status) {
|
|
103
|
+
return ["COMPLETED", "FAILED", "CANCELLED", "TIMED_OUT"].includes(status);
|
|
104
|
+
};
|
|
91
105
|
//run and then poll status
|
|
92
|
-
export var runSync = curry(function (baseUrl, apiKey, endpointId, request
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
106
|
+
export var runSync = curry(function (baseUrl, apiKey, endpointId, request, timeout) {
|
|
107
|
+
if (timeout === void 0) { timeout = 90000; }
|
|
108
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
109
|
+
var startTime, getRemainingTime, runResp, data, id, start;
|
|
110
|
+
return __generator(this, function (_a) {
|
|
111
|
+
switch (_a.label) {
|
|
112
|
+
case 0:
|
|
113
|
+
startTime = Date.now();
|
|
114
|
+
getRemainingTime = function () { return clamp(1000, 90000, timeout - (Date.now() - startTime)); };
|
|
115
|
+
return [4 /*yield*/, runsync(baseUrl, apiKey, endpointId, request, timeout)];
|
|
116
|
+
case 1:
|
|
117
|
+
runResp = _a.sent();
|
|
118
|
+
data = __assign({}, runResp);
|
|
119
|
+
id = data.id;
|
|
120
|
+
start = Date.now();
|
|
121
|
+
_a.label = 2;
|
|
122
|
+
case 2:
|
|
123
|
+
if (!!isCompleted(data.status)) return [3 /*break*/, 4];
|
|
124
|
+
if (Date.now() - start > timeout) {
|
|
125
|
+
print("".concat(id, " timed out after ").concat(timeout / 1000, " seconds"));
|
|
126
|
+
return [2 /*return*/, __assign(__assign({}, data), { started: true, completed: false })];
|
|
127
|
+
}
|
|
128
|
+
return [4 /*yield*/, statusSync(baseUrl, apiKey, endpointId, id, getRemainingTime())];
|
|
129
|
+
case 3:
|
|
130
|
+
data = _a.sent();
|
|
131
|
+
print("".concat(id, ": ").concat(data.status));
|
|
132
|
+
return [3 /*break*/, 2];
|
|
133
|
+
case 4: return [2 /*return*/, __assign(__assign({}, data), { started: true, completed: true, succeeded: data.status === "COMPLETED" })];
|
|
134
|
+
}
|
|
135
|
+
});
|
|
121
136
|
});
|
|
122
|
-
});
|
|
137
|
+
});
|
|
123
138
|
//wrapper over /status-sync
|
|
124
|
-
var statusSync = curry(function (baseUrl, apiKey, endpointId, requestId,
|
|
139
|
+
var statusSync = curry(function (baseUrl, apiKey, endpointId, requestId, timeout) {
|
|
140
|
+
if (timeout === void 0) { timeout = 90000; }
|
|
141
|
+
var wait = clamp(1000, 90000, timeout);
|
|
125
142
|
var url = getEndpointUrl(baseUrl, endpointId) + "/status-sync/" + requestId + "?wait=".concat(wait);
|
|
126
143
|
var authHeader = getAuthHeader(apiKey);
|
|
127
|
-
return handleErrorsStatus(axios.get(url, authHeader));
|
|
144
|
+
return handleErrorsStatus(axios.get(url, __assign({}, authHeader)));
|
|
128
145
|
});
|
|
129
146
|
//wrapper over /runsync
|
|
130
|
-
var runsync = curry(function (baseUrl, apiKey, endpointId, request) {
|
|
131
|
-
|
|
147
|
+
var runsync = curry(function (baseUrl, apiKey, endpointId, request, timeout) {
|
|
148
|
+
if (timeout === void 0) { timeout = 90000; }
|
|
149
|
+
var wait = clamp(1000, 90000, timeout);
|
|
150
|
+
var url = getEndpointUrl(baseUrl, endpointId) + "/runsync" + "?wait=".concat(wait);
|
|
132
151
|
var authHeader = getAuthHeader(apiKey);
|
|
133
|
-
return handleErrorsStatus(axios.post(url, request, authHeader));
|
|
152
|
+
return handleErrorsStatus(axios.post(url, request, __assign({}, authHeader)));
|
|
134
153
|
});
|
|
135
154
|
//wrapper over /run
|
|
136
|
-
export var run = curry(function (baseUrl, apiKey, endpointId, request) {
|
|
155
|
+
export var run = curry(function (baseUrl, apiKey, endpointId, request, timeout) {
|
|
156
|
+
if (timeout === void 0) { timeout = 3000; }
|
|
137
157
|
var url = getEndpointUrl(baseUrl, endpointId) + "/run";
|
|
138
158
|
var authHeader = getAuthHeader(apiKey);
|
|
139
|
-
return handleErrors(axios.post(url, request, authHeader));
|
|
159
|
+
return handleErrors(axios.post(url, request, __assign(__assign({}, authHeader), { timeout: timeout })));
|
|
140
160
|
});
|
|
141
161
|
//wrapper over /status
|
|
142
|
-
export var
|
|
162
|
+
export var status = curry(function (baseUrl, apiKey, endpointId, requestId, timeout) {
|
|
163
|
+
if (timeout === void 0) { timeout = 3000; }
|
|
143
164
|
var url = getEndpointUrl(baseUrl, endpointId) + "/status/" + requestId;
|
|
144
165
|
var authHeader = getAuthHeader(apiKey);
|
|
145
|
-
return handleErrorsStatus(axios.get(url, authHeader));
|
|
146
|
-
});
|
|
147
|
-
//wrapper over /stream
|
|
148
|
-
export var stream = curry(function (baseUrl, apiKey, endpointId, requestId) {
|
|
149
|
-
var url = getEndpointUrl(baseUrl, endpointId) + "/stream/" + requestId;
|
|
150
|
-
var authHeader = getAuthHeader(apiKey);
|
|
151
|
-
return handleErrors(axios.get(url, authHeader));
|
|
166
|
+
return handleErrorsStatus(axios.get(url, __assign(__assign({}, authHeader), { timeout: timeout })));
|
|
152
167
|
});
|
|
168
|
+
//generator yielding results of stream
|
|
169
|
+
export function stream(baseUrl, apiKey, endpointId, requestId, timeout) {
|
|
170
|
+
if (timeout === void 0) { timeout = 0; }
|
|
171
|
+
return __asyncGenerator(this, arguments, function stream_1() {
|
|
172
|
+
var completed, start, url, authHeader, resp, _i, _a, output;
|
|
173
|
+
return __generator(this, function (_b) {
|
|
174
|
+
switch (_b.label) {
|
|
175
|
+
case 0:
|
|
176
|
+
completed = false;
|
|
177
|
+
start = Date.now();
|
|
178
|
+
_b.label = 1;
|
|
179
|
+
case 1:
|
|
180
|
+
if (!!completed) return [3 /*break*/, 8];
|
|
181
|
+
url = getEndpointUrl(baseUrl, endpointId) + "/stream/" + requestId;
|
|
182
|
+
authHeader = getAuthHeader(apiKey);
|
|
183
|
+
return [4 /*yield*/, __await(handleErrors(axios.get(url, authHeader)))];
|
|
184
|
+
case 2:
|
|
185
|
+
resp = _b.sent();
|
|
186
|
+
if (timeout !== 0 && Date.now() - start > timeout) {
|
|
187
|
+
print("stream timed out after ".concat(timeout / 1000, " seconds"));
|
|
188
|
+
completed = true;
|
|
189
|
+
}
|
|
190
|
+
if (isCompleted(resp.status)) {
|
|
191
|
+
completed = true;
|
|
192
|
+
}
|
|
193
|
+
_i = 0, _a = resp === null || resp === void 0 ? void 0 : resp.stream;
|
|
194
|
+
_b.label = 3;
|
|
195
|
+
case 3:
|
|
196
|
+
if (!(_i < _a.length)) return [3 /*break*/, 7];
|
|
197
|
+
output = _a[_i];
|
|
198
|
+
return [4 /*yield*/, __await(output)];
|
|
199
|
+
case 4: return [4 /*yield*/, _b.sent()];
|
|
200
|
+
case 5:
|
|
201
|
+
_b.sent();
|
|
202
|
+
_b.label = 6;
|
|
203
|
+
case 6:
|
|
204
|
+
_i++;
|
|
205
|
+
return [3 /*break*/, 3];
|
|
206
|
+
case 7: return [3 /*break*/, 1];
|
|
207
|
+
case 8: return [2 /*return*/];
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
}
|
|
153
212
|
//wrapper over /cancel
|
|
154
|
-
var cancel = curry(function (baseUrl, apiKey, endpointId, requestId) {
|
|
213
|
+
var cancel = curry(function (baseUrl, apiKey, endpointId, requestId, timeout) {
|
|
214
|
+
if (timeout === void 0) { timeout = 3000; }
|
|
155
215
|
var url = getEndpointUrl(baseUrl, endpointId) + "/cancel/" + requestId;
|
|
156
216
|
var authHeader = getAuthHeader(apiKey);
|
|
157
|
-
return handleErrors(axios.post(url, {}, authHeader));
|
|
217
|
+
return handleErrors(axios.post(url, {}, __assign(__assign({}, authHeader), { timeout: timeout })));
|
|
158
218
|
});
|
|
159
219
|
//wrapper over /health
|
|
160
|
-
export var
|
|
220
|
+
export var health = curry(function (baseUrl, apiKey, endpointId, timeout) {
|
|
221
|
+
if (timeout === void 0) { timeout = 3000; }
|
|
161
222
|
var url = getEndpointUrl(baseUrl, endpointId) + "/health";
|
|
162
223
|
var authHeader = getAuthHeader(apiKey);
|
|
163
|
-
return handleErrors(axios.get(url, authHeader));
|
|
224
|
+
return handleErrors(axios.get(url, __assign(__assign({}, authHeader), { timeout: timeout })));
|
|
164
225
|
});
|
|
165
226
|
//wrapper over /purge-queue
|
|
166
|
-
export var purgeQueue = curry(function (baseUrl, apiKey, endpointId) {
|
|
227
|
+
export var purgeQueue = curry(function (baseUrl, apiKey, endpointId, timeout) {
|
|
228
|
+
if (timeout === void 0) { timeout = 3000; }
|
|
167
229
|
var url = getEndpointUrl(baseUrl, endpointId) + "/purge-queue";
|
|
168
230
|
var authHeader = getAuthHeader(apiKey);
|
|
169
|
-
return handleErrors(axios.post(url, {}, authHeader));
|
|
231
|
+
return handleErrors(axios.post(url, {}, __assign(__assign({}, authHeader), { timeout: timeout })));
|
|
170
232
|
});
|
|
171
233
|
var Endpoint = /** @class */ (function () {
|
|
172
234
|
function Endpoint(baseUrl, apiKey, endpointId) {
|
|
@@ -177,52 +239,64 @@ var Endpoint = /** @class */ (function () {
|
|
|
177
239
|
this.apiKey = apiKey;
|
|
178
240
|
this.endpointId = endpointId;
|
|
179
241
|
}
|
|
180
|
-
Endpoint.prototype.runSync = function (request) {
|
|
242
|
+
Endpoint.prototype.runSync = function (request, timeout) {
|
|
243
|
+
if (timeout === void 0) { timeout = 90000; }
|
|
181
244
|
return __awaiter(this, void 0, void 0, function () {
|
|
182
245
|
return __generator(this, function (_a) {
|
|
183
|
-
return [2 /*return*/, runSync(this.baseUrl, this.apiKey, this.endpointId, request)];
|
|
246
|
+
return [2 /*return*/, runSync(this.baseUrl, this.apiKey, this.endpointId, request, timeout)];
|
|
184
247
|
});
|
|
185
248
|
});
|
|
186
249
|
};
|
|
187
|
-
Endpoint.prototype.run = function (request) {
|
|
250
|
+
Endpoint.prototype.run = function (request, timeout) {
|
|
251
|
+
if (timeout === void 0) { timeout = 3000; }
|
|
188
252
|
return __awaiter(this, void 0, void 0, function () {
|
|
189
253
|
return __generator(this, function (_a) {
|
|
190
|
-
return [2 /*return*/, run(this.baseUrl, this.apiKey, this.endpointId, request)];
|
|
254
|
+
return [2 /*return*/, run(this.baseUrl, this.apiKey, this.endpointId, request, timeout)];
|
|
191
255
|
});
|
|
192
256
|
});
|
|
193
257
|
};
|
|
194
|
-
Endpoint.prototype.
|
|
258
|
+
Endpoint.prototype.status = function (requestId, timeout) {
|
|
259
|
+
if (timeout === void 0) { timeout = 3000; }
|
|
195
260
|
return __awaiter(this, void 0, void 0, function () {
|
|
196
261
|
return __generator(this, function (_a) {
|
|
197
|
-
return [2 /*return*/,
|
|
262
|
+
return [2 /*return*/, status(this.baseUrl, this.apiKey, this.endpointId, requestId, timeout)];
|
|
198
263
|
});
|
|
199
264
|
});
|
|
200
265
|
};
|
|
201
|
-
Endpoint.prototype.
|
|
266
|
+
Endpoint.prototype.statusSync = function (requestId, timeout) {
|
|
267
|
+
if (timeout === void 0) { timeout = 90000; }
|
|
202
268
|
return __awaiter(this, void 0, void 0, function () {
|
|
203
269
|
return __generator(this, function (_a) {
|
|
204
|
-
return [2 /*return*/,
|
|
270
|
+
return [2 /*return*/, statusSync(this.baseUrl, this.apiKey, this.endpointId, requestId, timeout)];
|
|
205
271
|
});
|
|
206
272
|
});
|
|
207
273
|
};
|
|
208
|
-
|
|
274
|
+
//default to no timeout
|
|
275
|
+
Endpoint.prototype.stream = function (requestId, timeout) {
|
|
276
|
+
if (timeout === void 0) { timeout = 0; }
|
|
277
|
+
return stream(this.baseUrl, this.apiKey, this.endpointId, requestId, timeout);
|
|
278
|
+
};
|
|
279
|
+
Endpoint.prototype.cancel = function (requestId, timeout) {
|
|
280
|
+
if (timeout === void 0) { timeout = 3000; }
|
|
209
281
|
return __awaiter(this, void 0, void 0, function () {
|
|
210
282
|
return __generator(this, function (_a) {
|
|
211
|
-
return [2 /*return*/, cancel(this.baseUrl, this.apiKey, this.endpointId, requestId)];
|
|
283
|
+
return [2 /*return*/, cancel(this.baseUrl, this.apiKey, this.endpointId, requestId, timeout)];
|
|
212
284
|
});
|
|
213
285
|
});
|
|
214
286
|
};
|
|
215
|
-
Endpoint.prototype.
|
|
287
|
+
Endpoint.prototype.health = function (timeout) {
|
|
288
|
+
if (timeout === void 0) { timeout = 3000; }
|
|
216
289
|
return __awaiter(this, void 0, void 0, function () {
|
|
217
290
|
return __generator(this, function (_a) {
|
|
218
|
-
return [2 /*return*/,
|
|
291
|
+
return [2 /*return*/, health(this.baseUrl, this.apiKey, this.endpointId, timeout)];
|
|
219
292
|
});
|
|
220
293
|
});
|
|
221
294
|
};
|
|
222
|
-
Endpoint.prototype.purgeQueue = function () {
|
|
295
|
+
Endpoint.prototype.purgeQueue = function (timeout) {
|
|
296
|
+
if (timeout === void 0) { timeout = 3000; }
|
|
223
297
|
return __awaiter(this, void 0, void 0, function () {
|
|
224
298
|
return __generator(this, function (_a) {
|
|
225
|
-
return [2 /*return*/, purgeQueue(this.baseUrl, this.apiKey, this.endpointId)];
|
|
299
|
+
return [2 /*return*/, purgeQueue(this.baseUrl, this.apiKey, this.endpointId, timeout)];
|
|
226
300
|
});
|
|
227
301
|
});
|
|
228
302
|
};
|
|
@@ -256,3 +330,4 @@ export default (function (apiKey, options) {
|
|
|
256
330
|
if (options === void 0) { options = defaultSdkOptions; }
|
|
257
331
|
return new RunpodSdk(apiKey, options);
|
|
258
332
|
});
|
|
333
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,KAAwB,MAAM,OAAO,CAAA;AAC5C,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,OAAO,CAAA;AA2D3C,IAAM,aAAa,GAAG,UAAC,MAAc,IAAK,OAAA,CAAC;IACzC,OAAO,EAAE;QACP,eAAe,EAAE,iBAAU,MAAM,CAAE;QACnC,cAAc,EAAE,kBAAkB;KACnC;CACF,CAAC,EALwC,CAKxC,CAAA;AACF,IA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AY,MAAc,EAAE,OAAmB;;QAFvC,WAAM,GAAW,EAAE,CAAA;QAC3B,YAAO,GAAW,2BAA2B,CAAA;QAE3C,IAAI,KAAK,CAAC,MAAM,CAAC,EAAE;YACjB,KAAK,CAAC,sBAAsB,CAAC,CAAA;YAC7B,OAAM;SACP;QACD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,OAAO,GAAG,MAAA,OAAO,CAAC,OAAO,mCAAI,IAAI,CAAC,OAAO,CAAA;IAChD,CAAC;IACD,4BAAQ,GAAR,UAAS,UAAkB;QACzB,IAAI,KAAK,CAAC,UAAU,CAAC,EAAE;YACrB,KAAK,CAAC,0BAA0B,CAAC,CAAA;YACjC,OAAO,IAAI,CAAA;SACZ;QACD,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;IAC5D,CAAC;IAGH,gBAAC;AAAD,CAAC,AApBD,IAoBC;AACD,gBAAe,UAAC,MAAc,EAAE,OAAuC;IAAvC,wBAAA,EAAA,2BAAuC;IACrE,OAAA,IAAI,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC;AAA9B,CAA8B,EAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import runpodSdk from "../dist/index.js"
|
|
2
|
+
const { RUNPOD_API_KEY } = process.env
|
|
3
|
+
if (!RUNPOD_API_KEY) {
|
|
4
|
+
console.log("please supply RUNPOD_API_KEY as an environment variable")
|
|
5
|
+
process.exit()
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const runpod = runpodSdk(RUNPOD_API_KEY)
|
|
9
|
+
const endpoint = runpod.endpoint("faster-whisper")
|
|
10
|
+
|
|
11
|
+
const input = {
|
|
12
|
+
input: {
|
|
13
|
+
audio: "https://github.com/runpod-workers/sample-inputs/raw/main/audio/gettysburg.wav",
|
|
14
|
+
model: "base",
|
|
15
|
+
},
|
|
16
|
+
}
|
|
17
|
+
const result = await endpoint.runSync(input)
|
|
18
|
+
|
|
19
|
+
console.log(result)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import runpodSdk from "../dist/index.js"
|
|
2
|
+
const { RUNPOD_API_KEY } = process.env
|
|
3
|
+
if (!RUNPOD_API_KEY) {
|
|
4
|
+
console.log("please supply RUNPOD_API_KEY as an environment variable")
|
|
5
|
+
process.exit()
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const runpod = runpodSdk(RUNPOD_API_KEY)
|
|
9
|
+
const endpoint = runpod.endpoint("faster-whisper")
|
|
10
|
+
const input = {
|
|
11
|
+
input: {
|
|
12
|
+
audio: "https://github.com/runpod-workers/sample-inputs/raw/main/audio/gettysburg.wav",
|
|
13
|
+
model: "base",
|
|
14
|
+
},
|
|
15
|
+
}
|
|
16
|
+
const result = await endpoint.run(input)
|
|
17
|
+
console.log("run resp")
|
|
18
|
+
console.log(result)
|
|
19
|
+
|
|
20
|
+
const { id } = result
|
|
21
|
+
const cancelResp = await endpoint.cancel(id)
|
|
22
|
+
console.log("cancel resp")
|
|
23
|
+
console.log(cancelResp)
|
|
24
|
+
|
|
25
|
+
const statusResp = await endpoint.status(id)
|
|
26
|
+
console.log("status after cancellation")
|
|
27
|
+
console.log(statusResp)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import runpodSdk, { runpodServerlessBaseUrlDev } from "../dist/index.js"
|
|
2
|
+
const { RUNPOD_API_KEY } = process.env
|
|
3
|
+
if (!RUNPOD_API_KEY) {
|
|
4
|
+
console.log("please supply RUNPOD_API_KEY as an environment variable")
|
|
5
|
+
process.exit()
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const runpod = runpodSdk(RUNPOD_API_KEY, { baseUrl: runpodServerlessBaseUrlDev })
|
|
9
|
+
const endpoint = runpod.endpoint("faster-whisper")
|
|
10
|
+
const input = {
|
|
11
|
+
input: {
|
|
12
|
+
audio: "https://github.com/runpod-workers/sample-inputs/raw/main/audio/gettysburg.wav",
|
|
13
|
+
model: "base",
|
|
14
|
+
},
|
|
15
|
+
}
|
|
16
|
+
const result = await endpoint.runSync(input)
|
|
17
|
+
console.log(result)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import runpodSdk from "../dist/index.js"
|
|
2
|
+
const { RUNPOD_API_KEY, ENDPOINT_ID } = process.env
|
|
3
|
+
if (!RUNPOD_API_KEY || !ENDPOINT_ID) {
|
|
4
|
+
console.log("please supply RUNPOD_API_KEY as an environment variable")
|
|
5
|
+
process.exit()
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const runpod = runpodSdk(RUNPOD_API_KEY)
|
|
9
|
+
const endpoint = runpod.endpoint(ENDPOINT_ID)
|
|
10
|
+
const result = await endpoint.health()
|
|
11
|
+
console.log(result)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import runpodSdk from "../dist/index.js"
|
|
2
|
+
const { RUNPOD_API_KEY } = process.env
|
|
3
|
+
if (!RUNPOD_API_KEY) {
|
|
4
|
+
console.log("please supply RUNPOD_API_KEY as an environment variable")
|
|
5
|
+
process.exit()
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const runpod = runpodSdk(RUNPOD_API_KEY)
|
|
9
|
+
const endpoint = runpod.endpoint("faster-whisper")
|
|
10
|
+
const result = await endpoint.health()
|
|
11
|
+
console.log(result)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import runpodSdk from "../dist/index.js"
|
|
2
|
+
const { RUNPOD_API_KEY, ENDPOINT_ID } = process.env
|
|
3
|
+
if (!RUNPOD_API_KEY || !ENDPOINT_ID) {
|
|
4
|
+
console.log("please supply RUNPOD_API_KEY as an environment variable")
|
|
5
|
+
process.exit()
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const runpod = runpodSdk(RUNPOD_API_KEY)
|
|
9
|
+
const endpoint = runpod.endpoint(ENDPOINT_ID)
|
|
10
|
+
const result = await endpoint.purgeQueue()
|
|
11
|
+
console.log(result)
|
package/examples/run.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import runpodSdk from "../dist/index.js"
|
|
2
|
+
const { RUNPOD_API_KEY } = process.env
|
|
3
|
+
if (!RUNPOD_API_KEY) {
|
|
4
|
+
console.log("please supply RUNPOD_API_KEY as an environment variable")
|
|
5
|
+
process.exit()
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const runpod = runpodSdk(RUNPOD_API_KEY)
|
|
9
|
+
const endpoint = runpod.endpoint("faster-whisper")
|
|
10
|
+
const input = {
|
|
11
|
+
input: {
|
|
12
|
+
audio: "https://github.com/runpod-workers/sample-inputs/raw/main/audio/gettysburg.wav",
|
|
13
|
+
model: "base",
|
|
14
|
+
},
|
|
15
|
+
}
|
|
16
|
+
const result = await endpoint.run(input)
|
|
17
|
+
console.log("run response")
|
|
18
|
+
console.log(result)
|
|
19
|
+
|
|
20
|
+
const { id } = result
|
|
21
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
|
|
22
|
+
for (let i = 0; i < 5; i++) {
|
|
23
|
+
const status = await endpoint.status(id)
|
|
24
|
+
console.log("status response")
|
|
25
|
+
console.log(status)
|
|
26
|
+
await sleep(1000)
|
|
27
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import runpodSdk from "../dist/index.js"
|
|
2
|
+
const { RUNPOD_API_KEY } = process.env
|
|
3
|
+
if (!RUNPOD_API_KEY) {
|
|
4
|
+
console.log("please supply RUNPOD_API_KEY as an environment variable")
|
|
5
|
+
process.exit()
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const runpod = runpodSdk(RUNPOD_API_KEY)
|
|
9
|
+
const endpoint = runpod.endpoint("faster-whisper")
|
|
10
|
+
const input = {
|
|
11
|
+
input: {
|
|
12
|
+
audio: "https://github.com/runpod-workers/sample-inputs/raw/main/audio/gettysburg.wav",
|
|
13
|
+
model: "base",
|
|
14
|
+
},
|
|
15
|
+
}
|
|
16
|
+
const result = await endpoint.runSync(input, 3000)
|
|
17
|
+
console.log(result)
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import runpodSdk from "runpod-sdk"
|
|
2
|
+
|
|
3
|
+
const { RUNPOD_API_KEY } = process.env
|
|
4
|
+
if (!RUNPOD_API_KEY) {
|
|
5
|
+
console.log("please supply RUNPOD_API_KEY as an environment variable")
|
|
6
|
+
process.exit()
|
|
7
|
+
}
|
|
8
|
+
const runpod = runpodSdk(RUNPOD_API_KEY)
|
|
9
|
+
//mock endpoint which returns whatever you specify as a stream
|
|
10
|
+
//with a specified delay between inputs
|
|
11
|
+
const endpoint = runpod.endpoint("gwp4kx5yd3nur1")
|
|
12
|
+
|
|
13
|
+
const request = {
|
|
14
|
+
input: {
|
|
15
|
+
mock_return: ["a", "b", "c", "d", "e", "f", "g"],
|
|
16
|
+
mock_delay: 2,
|
|
17
|
+
},
|
|
18
|
+
}
|
|
19
|
+
const runResp = await endpoint.run(request)
|
|
20
|
+
const { id } = runResp
|
|
21
|
+
for await (const result of endpoint.stream(id)) {
|
|
22
|
+
console.log(`stream yielded ${JSON.stringify(result, null, 2)}`)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Expected output
|
|
26
|
+
/*
|
|
27
|
+
stream yielded {
|
|
28
|
+
"output": "a",
|
|
29
|
+
}
|
|
30
|
+
stream yielded {
|
|
31
|
+
"output": "b"
|
|
32
|
+
}
|
|
33
|
+
stream yielded {
|
|
34
|
+
"output": "c"
|
|
35
|
+
}
|
|
36
|
+
stream yielded {
|
|
37
|
+
"output": "d"
|
|
38
|
+
}
|
|
39
|
+
stream yielded {
|
|
40
|
+
"output": "e"
|
|
41
|
+
}
|
|
42
|
+
stream yielded {
|
|
43
|
+
"output": "f"
|
|
44
|
+
}
|
|
45
|
+
stream yielded {
|
|
46
|
+
"output": "g"
|
|
47
|
+
}
|
|
48
|
+
*/
|
package/examples/test.js
CHANGED
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
import runpodSdk
|
|
1
|
+
import runpodSdk from "../dist/index.js"
|
|
2
2
|
|
|
3
|
-
const { RUNPOD_API_KEY } = process.env
|
|
4
|
-
if (!RUNPOD_API_KEY) {
|
|
5
|
-
console.log("please supply RUNPOD_API_KEY as an environment variable")
|
|
3
|
+
const { RUNPOD_API_KEY, ENDPOINT_ID } = process.env
|
|
4
|
+
if (!RUNPOD_API_KEY || !ENDPOINT_ID) {
|
|
5
|
+
console.log("please supply RUNPOD_API_KEY and ENDPOINT_ID as an environment variable")
|
|
6
6
|
process.exit()
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
8
|
+
const runpod = runpodSdk(RUNPOD_API_KEY)
|
|
9
|
+
const endpoint = runpod.endpoint(ENDPOINT_ID)
|
|
10
|
+
|
|
11
11
|
const request = {
|
|
12
12
|
input: {
|
|
13
13
|
prompt: "photo of a horse",
|
|
14
14
|
},
|
|
15
|
-
policy: {
|
|
16
|
-
executionTimeout: 120 * 1000,
|
|
17
|
-
},
|
|
18
15
|
}
|
|
19
16
|
|
|
20
17
|
console.log("\nrun")
|
|
@@ -22,20 +19,56 @@ const runResp = await endpoint.run(request)
|
|
|
22
19
|
console.log(runResp)
|
|
23
20
|
const { id: requestId } = runResp
|
|
24
21
|
console.log("\nstatus")
|
|
25
|
-
const statusResp = await endpoint.
|
|
22
|
+
const statusResp = await endpoint.status(requestId)
|
|
26
23
|
console.log(statusResp)
|
|
27
24
|
console.log("\ncancel")
|
|
28
25
|
const cancelResp = await endpoint.cancel(requestId)
|
|
29
26
|
console.log(cancelResp)
|
|
30
27
|
console.log("\nhealth")
|
|
31
|
-
const healthResp = await endpoint.
|
|
28
|
+
const healthResp = await endpoint.health()
|
|
32
29
|
console.log(healthResp)
|
|
33
30
|
console.log("\npurge queue")
|
|
34
31
|
const purgeResp = await endpoint.purgeQueue()
|
|
35
32
|
console.log(purgeResp)
|
|
36
33
|
console.log("\nafter purge")
|
|
37
|
-
console.log(await endpoint.
|
|
34
|
+
console.log(await endpoint.health())
|
|
38
35
|
|
|
39
36
|
console.log("runSync")
|
|
40
37
|
const result = await endpoint.runSync(request)
|
|
41
38
|
console.log(result)
|
|
39
|
+
|
|
40
|
+
const failingRequest = {
|
|
41
|
+
input: {
|
|
42
|
+
bogus_key: "photo of a horse",
|
|
43
|
+
},
|
|
44
|
+
}
|
|
45
|
+
console.log("runSync failing")
|
|
46
|
+
const failingResult = await endpoint.runSync(failingRequest)
|
|
47
|
+
console.log(failingResult)
|
|
48
|
+
|
|
49
|
+
const slowRequest = {
|
|
50
|
+
input: {
|
|
51
|
+
prompt: "photo of a horse",
|
|
52
|
+
num_inference_steps: 200,
|
|
53
|
+
},
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
console.log("runSync timed out")
|
|
57
|
+
const timedOutResult = await endpoint.runSync(slowRequest, 3000)
|
|
58
|
+
console.log(timedOutResult)
|
|
59
|
+
|
|
60
|
+
console.log("\nstream")
|
|
61
|
+
//mock endpoint which returns whatever you specify as a stream
|
|
62
|
+
//with a specified delay between inputs
|
|
63
|
+
const streamingEndpoint = runpod.endpoint("eqam4ya2iazibb")
|
|
64
|
+
const streamReq = {
|
|
65
|
+
input: {
|
|
66
|
+
mock_return: ["a", "b", "c", "d", "e", "f", "g"],
|
|
67
|
+
mock_delay: 2,
|
|
68
|
+
},
|
|
69
|
+
}
|
|
70
|
+
const streamRunResp = await streamingEndpoint.run(streamReq)
|
|
71
|
+
const { id } = streamRunResp
|
|
72
|
+
for await (const result of endpoint.stream(id)) {
|
|
73
|
+
console.log(`stream yielded ${JSON.stringify(result, null, 2)}`)
|
|
74
|
+
}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -9,14 +9,17 @@ export type S3Config = {
|
|
|
9
9
|
accessSecret: string
|
|
10
10
|
bucketName: string
|
|
11
11
|
endpointUrl: string
|
|
12
|
+
objectPath?: string
|
|
12
13
|
}
|
|
13
14
|
export type EndpointInputPayload = {
|
|
14
15
|
input: any
|
|
15
16
|
webhook?: string
|
|
17
|
+
webhookV2?: string
|
|
16
18
|
s3Config?: S3Config
|
|
17
19
|
policy?: ExecutionPolicy
|
|
18
20
|
}
|
|
19
21
|
export type EndpointIncompleteOutput = {
|
|
22
|
+
delayTime?: number
|
|
20
23
|
status: string
|
|
21
24
|
id: string
|
|
22
25
|
}
|
|
@@ -30,6 +33,11 @@ export type EndpointCompletedOutput = {
|
|
|
30
33
|
|
|
31
34
|
export type EndpointOutput = EndpointCompletedOutput | EndpointIncompleteOutput
|
|
32
35
|
|
|
36
|
+
export type EndpointStreamOutput = {
|
|
37
|
+
status: string
|
|
38
|
+
stream: [any]
|
|
39
|
+
}
|
|
40
|
+
|
|
33
41
|
export type CancelOutput = {
|
|
34
42
|
status: string
|
|
35
43
|
id: string
|
|
@@ -58,7 +66,6 @@ const getAuthHeader = (apiKey: string) => ({
|
|
|
58
66
|
},
|
|
59
67
|
})
|
|
60
68
|
const print = console.log
|
|
61
|
-
const sleep = (ms: any) => new Promise((resolve: any) => setTimeout(resolve, ms))
|
|
62
69
|
|
|
63
70
|
const handleErrors = async (axiosRequest: Promise<AxiosResponse>) => {
|
|
64
71
|
const resp = await axiosRequest
|
|
@@ -77,27 +84,34 @@ const handleErrorsStatus = async (axiosRequest: Promise<AxiosResponse>) => {
|
|
|
77
84
|
return {
|
|
78
85
|
...resp.data,
|
|
79
86
|
started: true,
|
|
80
|
-
completed:
|
|
87
|
+
completed: isCompleted(resp.data.status),
|
|
81
88
|
succeeded: resp.data.status === "COMPLETED",
|
|
82
89
|
}
|
|
83
90
|
}
|
|
84
91
|
export const runpodServerlessBaseUrlProd = "https://api.runpod.ai/v2"
|
|
85
92
|
export const runpodServerlessBaseUrlDev = "https://dev-api.runpod.ai/v2"
|
|
86
93
|
const getEndpointUrl = curry((baseUrl, endpointId: string) => `${baseUrl}/${endpointId}`)
|
|
94
|
+
const isCompleted = (status: string) =>
|
|
95
|
+
["COMPLETED", "FAILED", "CANCELLED", "TIMED_OUT"].includes(status)
|
|
87
96
|
|
|
88
97
|
//run and then poll status
|
|
89
98
|
export const runSync = curry(
|
|
90
|
-
async (
|
|
91
|
-
|
|
99
|
+
async (
|
|
100
|
+
baseUrl: string,
|
|
101
|
+
apiKey: string,
|
|
102
|
+
endpointId: string,
|
|
103
|
+
request: EndpointInputPayload,
|
|
104
|
+
timeout: number = 90000
|
|
105
|
+
) => {
|
|
92
106
|
const startTime = Date.now()
|
|
93
|
-
const getRemainingTime = () => clamp(1000, 90000,
|
|
94
|
-
const runResp: any = await runsync(baseUrl, apiKey, endpointId, request)
|
|
107
|
+
const getRemainingTime = () => clamp(1000, 90000, timeout - (Date.now() - startTime))
|
|
108
|
+
const runResp: any = await runsync(baseUrl, apiKey, endpointId, request, timeout)
|
|
95
109
|
let data: EndpointOutput = { ...runResp }
|
|
96
110
|
const { id } = data
|
|
97
111
|
const start = Date.now()
|
|
98
|
-
while (!
|
|
99
|
-
if (Date.now() - start >
|
|
100
|
-
print(`${id} timed out after ${
|
|
112
|
+
while (!isCompleted(data.status)) {
|
|
113
|
+
if (Date.now() - start > timeout) {
|
|
114
|
+
print(`${id} timed out after ${timeout / 1000} seconds`)
|
|
101
115
|
return { ...data, started: true, completed: false }
|
|
102
116
|
}
|
|
103
117
|
data = await statusSync(baseUrl, apiKey, endpointId, id, getRemainingTime())
|
|
@@ -109,64 +123,122 @@ export const runSync = curry(
|
|
|
109
123
|
|
|
110
124
|
//wrapper over /status-sync
|
|
111
125
|
const statusSync = curry(
|
|
112
|
-
(
|
|
126
|
+
(
|
|
127
|
+
baseUrl: string,
|
|
128
|
+
apiKey: string,
|
|
129
|
+
endpointId: string,
|
|
130
|
+
requestId: String,
|
|
131
|
+
timeout: number = 90000
|
|
132
|
+
) => {
|
|
133
|
+
const wait = clamp(1000, 90000, timeout)
|
|
113
134
|
const url = getEndpointUrl(baseUrl, endpointId) + "/status-sync/" + requestId + `?wait=${wait}`
|
|
114
135
|
const authHeader = getAuthHeader(apiKey)
|
|
115
|
-
return handleErrorsStatus(axios.get(url, authHeader))
|
|
136
|
+
return handleErrorsStatus(axios.get(url, { ...authHeader }))
|
|
116
137
|
}
|
|
117
138
|
)
|
|
118
139
|
|
|
119
140
|
//wrapper over /runsync
|
|
120
141
|
const runsync = curry(
|
|
121
|
-
(
|
|
122
|
-
|
|
142
|
+
(
|
|
143
|
+
baseUrl: string,
|
|
144
|
+
apiKey: string,
|
|
145
|
+
endpointId: string,
|
|
146
|
+
request: EndpointInputPayload,
|
|
147
|
+
timeout: number = 90000
|
|
148
|
+
) => {
|
|
149
|
+
const wait = clamp(1000, 90000, timeout)
|
|
150
|
+
const url = getEndpointUrl(baseUrl, endpointId) + "/runsync" + `?wait=${wait}`
|
|
123
151
|
const authHeader = getAuthHeader(apiKey)
|
|
124
|
-
return handleErrorsStatus(axios.post(url, request, authHeader))
|
|
152
|
+
return handleErrorsStatus(axios.post(url, request, { ...authHeader }))
|
|
125
153
|
}
|
|
126
154
|
)
|
|
127
155
|
|
|
128
156
|
//wrapper over /run
|
|
129
157
|
export const run = curry(
|
|
130
|
-
(
|
|
158
|
+
(
|
|
159
|
+
baseUrl: string,
|
|
160
|
+
apiKey: string,
|
|
161
|
+
endpointId: string,
|
|
162
|
+
request: EndpointInputPayload,
|
|
163
|
+
timeout: number = 3000
|
|
164
|
+
) => {
|
|
131
165
|
const url = getEndpointUrl(baseUrl, endpointId) + "/run"
|
|
132
166
|
const authHeader = getAuthHeader(apiKey)
|
|
133
|
-
return handleErrors(axios.post(url, request, authHeader))
|
|
167
|
+
return handleErrors(axios.post(url, request, { ...authHeader, timeout }))
|
|
134
168
|
}
|
|
135
169
|
)
|
|
136
170
|
//wrapper over /status
|
|
137
|
-
export const
|
|
138
|
-
(
|
|
171
|
+
export const status = curry(
|
|
172
|
+
(
|
|
173
|
+
baseUrl: string,
|
|
174
|
+
apiKey: string,
|
|
175
|
+
endpointId: string,
|
|
176
|
+
requestId: string,
|
|
177
|
+
timeout: number = 3000
|
|
178
|
+
) => {
|
|
139
179
|
const url = getEndpointUrl(baseUrl, endpointId) + "/status/" + requestId
|
|
140
180
|
const authHeader = getAuthHeader(apiKey)
|
|
141
|
-
return handleErrorsStatus(axios.get(url, authHeader))
|
|
181
|
+
return handleErrorsStatus(axios.get(url, { ...authHeader, timeout }))
|
|
142
182
|
}
|
|
143
183
|
)
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
184
|
+
|
|
185
|
+
//generator yielding results of stream
|
|
186
|
+
export async function* stream(
|
|
187
|
+
baseUrl: string,
|
|
188
|
+
apiKey: string,
|
|
189
|
+
endpointId: string,
|
|
190
|
+
requestId: string,
|
|
191
|
+
timeout: number = 0
|
|
192
|
+
) {
|
|
193
|
+
let completed = false
|
|
194
|
+
const start = Date.now()
|
|
195
|
+
while (!completed) {
|
|
147
196
|
const url = getEndpointUrl(baseUrl, endpointId) + "/stream/" + requestId
|
|
148
197
|
const authHeader = getAuthHeader(apiKey)
|
|
149
|
-
|
|
198
|
+
const resp = await handleErrors(axios.get(url, authHeader))
|
|
199
|
+
if (timeout !== 0 && Date.now() - start > timeout) {
|
|
200
|
+
print(`stream timed out after ${timeout / 1000} seconds`)
|
|
201
|
+
completed = true
|
|
202
|
+
}
|
|
203
|
+
if (isCompleted(resp.status)) {
|
|
204
|
+
completed = true
|
|
205
|
+
}
|
|
206
|
+
for (const output of resp?.stream) {
|
|
207
|
+
yield output
|
|
208
|
+
}
|
|
150
209
|
}
|
|
151
|
-
|
|
210
|
+
}
|
|
211
|
+
|
|
152
212
|
//wrapper over /cancel
|
|
153
|
-
const cancel = curry(
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
213
|
+
const cancel = curry(
|
|
214
|
+
(
|
|
215
|
+
baseUrl: string,
|
|
216
|
+
apiKey: string,
|
|
217
|
+
endpointId: string,
|
|
218
|
+
requestId: string,
|
|
219
|
+
timeout: number = 3000
|
|
220
|
+
) => {
|
|
221
|
+
const url = getEndpointUrl(baseUrl, endpointId) + "/cancel/" + requestId
|
|
222
|
+
const authHeader = getAuthHeader(apiKey)
|
|
223
|
+
return handleErrors(axios.post(url, {}, { ...authHeader, timeout }))
|
|
224
|
+
}
|
|
225
|
+
)
|
|
158
226
|
//wrapper over /health
|
|
159
|
-
export const
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
})
|
|
227
|
+
export const health = curry(
|
|
228
|
+
(baseUrl: string, apiKey: string, endpointId: string, timeout: number = 3000) => {
|
|
229
|
+
const url = getEndpointUrl(baseUrl, endpointId) + "/health"
|
|
230
|
+
const authHeader = getAuthHeader(apiKey)
|
|
231
|
+
return handleErrors(axios.get(url, { ...authHeader, timeout }))
|
|
232
|
+
}
|
|
233
|
+
)
|
|
164
234
|
//wrapper over /purge-queue
|
|
165
|
-
export const purgeQueue = curry(
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
})
|
|
235
|
+
export const purgeQueue = curry(
|
|
236
|
+
(baseUrl: string, apiKey: string, endpointId: string, timeout: number = 3000) => {
|
|
237
|
+
const url = getEndpointUrl(baseUrl, endpointId) + "/purge-queue"
|
|
238
|
+
const authHeader = getAuthHeader(apiKey)
|
|
239
|
+
return handleErrors(axios.post(url, {}, { ...authHeader, timeout }))
|
|
240
|
+
}
|
|
241
|
+
)
|
|
170
242
|
|
|
171
243
|
class Endpoint {
|
|
172
244
|
endpointId: string = ""
|
|
@@ -177,26 +249,33 @@ class Endpoint {
|
|
|
177
249
|
this.apiKey = apiKey
|
|
178
250
|
this.endpointId = endpointId
|
|
179
251
|
}
|
|
180
|
-
async runSync(
|
|
181
|
-
|
|
252
|
+
async runSync(
|
|
253
|
+
request: EndpointInputPayload,
|
|
254
|
+
timeout: number = 90000
|
|
255
|
+
): Promise<EndpointCompletedOutput> {
|
|
256
|
+
return runSync(this.baseUrl, this.apiKey, this.endpointId, request, timeout)
|
|
257
|
+
}
|
|
258
|
+
async run(request: EndpointInputPayload, timeout: number = 3000): Promise<string> {
|
|
259
|
+
return run(this.baseUrl, this.apiKey, this.endpointId, request, timeout)
|
|
182
260
|
}
|
|
183
|
-
async
|
|
184
|
-
return
|
|
261
|
+
async status(requestId: string, timeout: number = 3000): Promise<EndpointOutput> {
|
|
262
|
+
return status(this.baseUrl, this.apiKey, this.endpointId, requestId, timeout)
|
|
185
263
|
}
|
|
186
|
-
async
|
|
187
|
-
return
|
|
264
|
+
async statusSync(requestId: string, timeout: number = 90000): Promise<EndpointOutput> {
|
|
265
|
+
return statusSync(this.baseUrl, this.apiKey, this.endpointId, requestId, timeout)
|
|
188
266
|
}
|
|
189
|
-
|
|
190
|
-
|
|
267
|
+
//default to no timeout
|
|
268
|
+
stream(requestId: string, timeout: number = 0): AsyncGenerator<any> {
|
|
269
|
+
return stream(this.baseUrl, this.apiKey, this.endpointId, requestId, timeout)
|
|
191
270
|
}
|
|
192
|
-
async cancel(requestId: string): Promise<CancelOutput> {
|
|
193
|
-
return cancel(this.baseUrl, this.apiKey, this.endpointId, requestId)
|
|
271
|
+
async cancel(requestId: string, timeout: number = 3000): Promise<CancelOutput> {
|
|
272
|
+
return cancel(this.baseUrl, this.apiKey, this.endpointId, requestId, timeout)
|
|
194
273
|
}
|
|
195
|
-
async
|
|
196
|
-
return
|
|
274
|
+
async health(timeout: number = 3000): Promise<HealthCheck> {
|
|
275
|
+
return health(this.baseUrl, this.apiKey, this.endpointId, timeout)
|
|
197
276
|
}
|
|
198
|
-
async purgeQueue(): Promise<PurgeQueueOutput> {
|
|
199
|
-
return purgeQueue(this.baseUrl, this.apiKey, this.endpointId)
|
|
277
|
+
async purgeQueue(timeout: number = 3000): Promise<PurgeQueueOutput> {
|
|
278
|
+
return purgeQueue(this.baseUrl, this.apiKey, this.endpointId, timeout)
|
|
200
279
|
}
|
|
201
280
|
}
|
|
202
281
|
|
package/tsconfig.json
CHANGED
package/examples/example.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import runpodSdk from "runpod-sdk"
|
|
2
|
-
|
|
3
|
-
const { RUNPOD_API_KEY, ENDPOINT_ID } = process.env
|
|
4
|
-
if (!(RUNPOD_API_KEY && ENDPOINT_ID)) {
|
|
5
|
-
console.log("please supply RUNPOD_API_KEY and ENDPOINT_ID as environment variables")
|
|
6
|
-
process.exit()
|
|
7
|
-
}
|
|
8
|
-
const runpod = runpodSdk(RUNPOD_API_KEY)
|
|
9
|
-
const endpoint = runpod.endpoint(ENDPOINT_ID)
|
|
10
|
-
|
|
11
|
-
const result = await endpoint.runSync({
|
|
12
|
-
input: {
|
|
13
|
-
prompt: "photo of a horse",
|
|
14
|
-
},
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
console.log(result)
|