runpod-sdk 1.0.4 → 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 +42 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +13 -7
- package/dist/index.js.map +1 -1
- package/examples/test.js +16 -0
- package/package.json +1 -1
- package/src/index.ts +13 -6
package/README.md
CHANGED
|
@@ -32,7 +32,7 @@ const { id } = 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,7 +56,7 @@ 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
61
|
|
|
62
62
|
Some Runpod endpoints are configured to yield multiple results for a single input, which can be streamed locally:
|
|
@@ -75,3 +75,43 @@ for await (const result of endpoint.stream(id)) {
|
|
|
75
75
|
```
|
|
76
76
|
|
|
77
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,6 +11,7 @@ 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
|
};
|
|
@@ -95,7 +96,7 @@ export declare const runSync: import("ts-toolbelt/out/Function/Curry").Curry<(ba
|
|
|
95
96
|
}>>;
|
|
96
97
|
export declare const run: import("ts-toolbelt/out/Function/Curry").Curry<(baseUrl: string, apiKey: string, endpointId: string, request: EndpointInputPayload, timeout?: number) => Promise<any>>;
|
|
97
98
|
export declare const status: import("ts-toolbelt/out/Function/Curry").Curry<(baseUrl: string, apiKey: string, endpointId: string, requestId: string, timeout?: number) => Promise<any>>;
|
|
98
|
-
export declare function stream(baseUrl: string, apiKey: string, endpointId: string, requestId: string): AsyncGenerator<any, void, unknown>;
|
|
99
|
+
export declare function stream(baseUrl: string, apiKey: string, endpointId: string, requestId: string, timeout?: number): AsyncGenerator<any, void, unknown>;
|
|
99
100
|
export declare const health: import("ts-toolbelt/out/Function/Curry").Curry<(baseUrl: string, apiKey: string, endpointId: string, timeout?: number) => Promise<any>>;
|
|
100
101
|
export declare const purgeQueue: import("ts-toolbelt/out/Function/Curry").Curry<(baseUrl: string, apiKey: string, endpointId: string, timeout?: number) => Promise<any>>;
|
|
101
102
|
declare class Endpoint {
|
|
@@ -107,7 +108,7 @@ declare class Endpoint {
|
|
|
107
108
|
run(request: EndpointInputPayload, timeout?: number): Promise<string>;
|
|
108
109
|
status(requestId: string, timeout?: number): Promise<EndpointOutput>;
|
|
109
110
|
statusSync(requestId: string, timeout?: number): Promise<EndpointOutput>;
|
|
110
|
-
stream(requestId: string): AsyncGenerator<any>;
|
|
111
|
+
stream(requestId: string, timeout?: number): AsyncGenerator<any>;
|
|
111
112
|
cancel(requestId: string, timeout?: number): Promise<CancelOutput>;
|
|
112
113
|
health(timeout?: number): Promise<HealthCheck>;
|
|
113
114
|
purgeQueue(timeout?: number): Promise<PurgeQueueOutput>;
|
package/dist/index.js
CHANGED
|
@@ -139,7 +139,6 @@ export var runSync = curry(function (baseUrl, apiKey, endpointId, request, timeo
|
|
|
139
139
|
var statusSync = curry(function (baseUrl, apiKey, endpointId, requestId, timeout) {
|
|
140
140
|
if (timeout === void 0) { timeout = 90000; }
|
|
141
141
|
var wait = clamp(1000, 90000, timeout);
|
|
142
|
-
console.log("statusSync wait", wait);
|
|
143
142
|
var url = getEndpointUrl(baseUrl, endpointId) + "/status-sync/" + requestId + "?wait=".concat(wait);
|
|
144
143
|
var authHeader = getAuthHeader(apiKey);
|
|
145
144
|
return handleErrorsStatus(axios.get(url, __assign({}, authHeader)));
|
|
@@ -148,7 +147,6 @@ var statusSync = curry(function (baseUrl, apiKey, endpointId, requestId, timeout
|
|
|
148
147
|
var runsync = curry(function (baseUrl, apiKey, endpointId, request, timeout) {
|
|
149
148
|
if (timeout === void 0) { timeout = 90000; }
|
|
150
149
|
var wait = clamp(1000, 90000, timeout);
|
|
151
|
-
console.log("runsync wait:", wait);
|
|
152
150
|
var url = getEndpointUrl(baseUrl, endpointId) + "/runsync" + "?wait=".concat(wait);
|
|
153
151
|
var authHeader = getAuthHeader(apiKey);
|
|
154
152
|
return handleErrorsStatus(axios.post(url, request, __assign({}, authHeader)));
|
|
@@ -165,16 +163,18 @@ export var status = curry(function (baseUrl, apiKey, endpointId, requestId, time
|
|
|
165
163
|
if (timeout === void 0) { timeout = 3000; }
|
|
166
164
|
var url = getEndpointUrl(baseUrl, endpointId) + "/status/" + requestId;
|
|
167
165
|
var authHeader = getAuthHeader(apiKey);
|
|
168
|
-
return handleErrorsStatus(axios.get(url, authHeader));
|
|
166
|
+
return handleErrorsStatus(axios.get(url, __assign(__assign({}, authHeader), { timeout: timeout })));
|
|
169
167
|
});
|
|
170
168
|
//generator yielding results of stream
|
|
171
|
-
export function stream(baseUrl, apiKey, endpointId, requestId) {
|
|
169
|
+
export function stream(baseUrl, apiKey, endpointId, requestId, timeout) {
|
|
170
|
+
if (timeout === void 0) { timeout = 0; }
|
|
172
171
|
return __asyncGenerator(this, arguments, function stream_1() {
|
|
173
|
-
var completed, url, authHeader, resp, _i, _a, output;
|
|
172
|
+
var completed, start, url, authHeader, resp, _i, _a, output;
|
|
174
173
|
return __generator(this, function (_b) {
|
|
175
174
|
switch (_b.label) {
|
|
176
175
|
case 0:
|
|
177
176
|
completed = false;
|
|
177
|
+
start = Date.now();
|
|
178
178
|
_b.label = 1;
|
|
179
179
|
case 1:
|
|
180
180
|
if (!!completed) return [3 /*break*/, 8];
|
|
@@ -183,6 +183,10 @@ export function stream(baseUrl, apiKey, endpointId, requestId) {
|
|
|
183
183
|
return [4 /*yield*/, __await(handleErrors(axios.get(url, authHeader)))];
|
|
184
184
|
case 2:
|
|
185
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
|
+
}
|
|
186
190
|
if (isCompleted(resp.status)) {
|
|
187
191
|
completed = true;
|
|
188
192
|
}
|
|
@@ -267,8 +271,10 @@ var Endpoint = /** @class */ (function () {
|
|
|
267
271
|
});
|
|
268
272
|
});
|
|
269
273
|
};
|
|
270
|
-
|
|
271
|
-
|
|
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);
|
|
272
278
|
};
|
|
273
279
|
Endpoint.prototype.cancel = function (requestId, timeout) {
|
|
274
280
|
if (timeout === void 0) { timeout = 3000; }
|
package/dist/index.js.map
CHANGED
|
@@ -1 +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;
|
|
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,IAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAA;AAEzB,IAAM,YAAY,GAAG,UAAO,YAAoC;;;;oBACjD,qBAAM,YAA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I,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"}
|
package/examples/test.js
CHANGED
|
@@ -56,3 +56,19 @@ const slowRequest = {
|
|
|
56
56
|
console.log("runSync timed out")
|
|
57
57
|
const timedOutResult = await endpoint.runSync(slowRequest, 3000)
|
|
58
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,10 +9,12 @@ 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
|
}
|
|
@@ -129,7 +131,6 @@ const statusSync = curry(
|
|
|
129
131
|
timeout: number = 90000
|
|
130
132
|
) => {
|
|
131
133
|
const wait = clamp(1000, 90000, timeout)
|
|
132
|
-
console.log("statusSync wait", wait)
|
|
133
134
|
const url = getEndpointUrl(baseUrl, endpointId) + "/status-sync/" + requestId + `?wait=${wait}`
|
|
134
135
|
const authHeader = getAuthHeader(apiKey)
|
|
135
136
|
return handleErrorsStatus(axios.get(url, { ...authHeader }))
|
|
@@ -146,7 +147,6 @@ const runsync = curry(
|
|
|
146
147
|
timeout: number = 90000
|
|
147
148
|
) => {
|
|
148
149
|
const wait = clamp(1000, 90000, timeout)
|
|
149
|
-
console.log("runsync wait:", wait)
|
|
150
150
|
const url = getEndpointUrl(baseUrl, endpointId) + "/runsync" + `?wait=${wait}`
|
|
151
151
|
const authHeader = getAuthHeader(apiKey)
|
|
152
152
|
return handleErrorsStatus(axios.post(url, request, { ...authHeader }))
|
|
@@ -178,7 +178,7 @@ export const status = curry(
|
|
|
178
178
|
) => {
|
|
179
179
|
const url = getEndpointUrl(baseUrl, endpointId) + "/status/" + requestId
|
|
180
180
|
const authHeader = getAuthHeader(apiKey)
|
|
181
|
-
return handleErrorsStatus(axios.get(url, authHeader))
|
|
181
|
+
return handleErrorsStatus(axios.get(url, { ...authHeader, timeout }))
|
|
182
182
|
}
|
|
183
183
|
)
|
|
184
184
|
|
|
@@ -187,13 +187,19 @@ export async function* stream(
|
|
|
187
187
|
baseUrl: string,
|
|
188
188
|
apiKey: string,
|
|
189
189
|
endpointId: string,
|
|
190
|
-
requestId: string
|
|
190
|
+
requestId: string,
|
|
191
|
+
timeout: number = 0
|
|
191
192
|
) {
|
|
192
193
|
let completed = false
|
|
194
|
+
const start = Date.now()
|
|
193
195
|
while (!completed) {
|
|
194
196
|
const url = getEndpointUrl(baseUrl, endpointId) + "/stream/" + requestId
|
|
195
197
|
const authHeader = getAuthHeader(apiKey)
|
|
196
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
|
+
}
|
|
197
203
|
if (isCompleted(resp.status)) {
|
|
198
204
|
completed = true
|
|
199
205
|
}
|
|
@@ -258,8 +264,9 @@ class Endpoint {
|
|
|
258
264
|
async statusSync(requestId: string, timeout: number = 90000): Promise<EndpointOutput> {
|
|
259
265
|
return statusSync(this.baseUrl, this.apiKey, this.endpointId, requestId, timeout)
|
|
260
266
|
}
|
|
261
|
-
|
|
262
|
-
|
|
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)
|
|
263
270
|
}
|
|
264
271
|
async cancel(requestId: string, timeout: number = 3000): Promise<CancelOutput> {
|
|
265
272
|
return cancel(this.baseUrl, this.apiKey, this.endpointId, requestId, timeout)
|