runpod-sdk 1.0.0 → 1.0.2
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 +4 -4
- package/dist/index.d.ts +104 -0
- package/examples/example.js +17 -0
- package/{test → examples}/test.js +2 -10
- package/package.json +2 -1
- package/tsconfig.json +2 -1
package/README.md
CHANGED
|
@@ -6,11 +6,11 @@ JavaScript client sdk for runpod
|
|
|
6
6
|
|
|
7
7
|
```js
|
|
8
8
|
const { RUNPOD_API_KEY, ENDPOINT_ID } = process.env;
|
|
9
|
-
import runpodSdk from "
|
|
9
|
+
import runpodSdk from "runpod-sdk";
|
|
10
10
|
|
|
11
11
|
const runpod = runpodSdk(RUNPOD_API_KEY);
|
|
12
12
|
const endpoint = runpod.endpoint(ENDPOINT_ID);
|
|
13
|
-
const result = await endpoint.
|
|
13
|
+
const result = await endpoint.runSync({
|
|
14
14
|
input: {
|
|
15
15
|
prompt: "a photo of a horse the size of a Boeing 787",
|
|
16
16
|
},
|
|
@@ -37,10 +37,10 @@ const status = await endpoint.getStatus(requestId);
|
|
|
37
37
|
|
|
38
38
|
If the request has been completed, the status object returned will contain the `output` of the request.
|
|
39
39
|
|
|
40
|
-
If you don't want to manage polling for request completion yourself, you can simply call `
|
|
40
|
+
If you don't want to manage polling for request completion yourself, you can simply call `runSync`, which will enqueue the request and then poll until the request completes, fails or times out.
|
|
41
41
|
|
|
42
42
|
```js
|
|
43
|
-
const result = await endpoint.
|
|
43
|
+
const result = await endpoint.runSync({
|
|
44
44
|
input: {
|
|
45
45
|
prompt: "a photo of a horse the size of a Boeing 787",
|
|
46
46
|
},
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
export type ExecutionPolicy = {
|
|
2
|
+
ttl?: number;
|
|
3
|
+
executionTimeout?: number;
|
|
4
|
+
};
|
|
5
|
+
export type S3Config = {
|
|
6
|
+
accessId: string;
|
|
7
|
+
accessSecret: string;
|
|
8
|
+
bucketName: string;
|
|
9
|
+
endpointUrl: string;
|
|
10
|
+
};
|
|
11
|
+
export type EndpointInputPayload = {
|
|
12
|
+
input: any;
|
|
13
|
+
webhook?: string;
|
|
14
|
+
s3Config?: S3Config;
|
|
15
|
+
policy?: ExecutionPolicy;
|
|
16
|
+
};
|
|
17
|
+
export type EndpointIncompleteOutput = {
|
|
18
|
+
status: string;
|
|
19
|
+
id: string;
|
|
20
|
+
};
|
|
21
|
+
export type EndpointCompletedOutput = {
|
|
22
|
+
status: string;
|
|
23
|
+
id: string;
|
|
24
|
+
output: any;
|
|
25
|
+
executionTime: number;
|
|
26
|
+
delayTime: number;
|
|
27
|
+
};
|
|
28
|
+
export type EndpointOutput = EndpointCompletedOutput | EndpointIncompleteOutput;
|
|
29
|
+
export type CancelOutput = {
|
|
30
|
+
status: string;
|
|
31
|
+
id: string;
|
|
32
|
+
executionTime: number;
|
|
33
|
+
delayTime: number;
|
|
34
|
+
};
|
|
35
|
+
export type HealthCheck = {
|
|
36
|
+
jobs: {
|
|
37
|
+
completed: number;
|
|
38
|
+
failed: number;
|
|
39
|
+
inProgress: number;
|
|
40
|
+
inQueue: number;
|
|
41
|
+
retried: number;
|
|
42
|
+
};
|
|
43
|
+
workers: {
|
|
44
|
+
idle: number;
|
|
45
|
+
initializing: number;
|
|
46
|
+
ready: number;
|
|
47
|
+
running: number;
|
|
48
|
+
throttled: number;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
export type PurgeQueueOutput = {
|
|
52
|
+
removed: number;
|
|
53
|
+
status: string;
|
|
54
|
+
};
|
|
55
|
+
export declare const runSync: import("ts-toolbelt/out/Function/Curry").Curry<(apiKey: string, endpointId: string, request: EndpointInputPayload) => Promise<{
|
|
56
|
+
started: boolean;
|
|
57
|
+
completed: boolean;
|
|
58
|
+
status: string;
|
|
59
|
+
id: string;
|
|
60
|
+
} | {
|
|
61
|
+
started: boolean;
|
|
62
|
+
completed: boolean;
|
|
63
|
+
status: string;
|
|
64
|
+
id: string;
|
|
65
|
+
output: any;
|
|
66
|
+
executionTime: number;
|
|
67
|
+
delayTime: number;
|
|
68
|
+
} | {
|
|
69
|
+
started: boolean;
|
|
70
|
+
completed: boolean;
|
|
71
|
+
succeeded: boolean;
|
|
72
|
+
status: string;
|
|
73
|
+
id: string;
|
|
74
|
+
} | {
|
|
75
|
+
started: boolean;
|
|
76
|
+
completed: boolean;
|
|
77
|
+
succeeded: boolean;
|
|
78
|
+
status: string;
|
|
79
|
+
id: string;
|
|
80
|
+
output: any;
|
|
81
|
+
executionTime: number;
|
|
82
|
+
delayTime: number;
|
|
83
|
+
}>>;
|
|
84
|
+
export declare const run: import("ts-toolbelt/out/Function/Curry").Curry<(apiKey: string, endpointId: string, request: EndpointInputPayload) => Promise<any>>;
|
|
85
|
+
export declare const getStatus: import("ts-toolbelt/out/Function/Curry").Curry<(apiKey: string, endpointId: string, requestId: string) => Promise<any>>;
|
|
86
|
+
export declare const stream: import("ts-toolbelt/out/Function/Curry").Curry<(apiKey: string, endpointId: string, requestId: string) => Promise<any>>;
|
|
87
|
+
export declare const getHealth: import("ts-toolbelt/out/Function/Curry").Curry<(apiKey: string, endpointId: string) => Promise<any>>;
|
|
88
|
+
export declare const purgeQueue: import("ts-toolbelt/out/Function/Curry").Curry<(apiKey: string, endpointId: string) => Promise<any>>;
|
|
89
|
+
declare class Endpoint {
|
|
90
|
+
endpointId: string;
|
|
91
|
+
private apiKey;
|
|
92
|
+
constructor(apiKey: string, endpointId: string);
|
|
93
|
+
runSync(request: EndpointInputPayload): Promise<EndpointCompletedOutput>;
|
|
94
|
+
run(request: EndpointInputPayload): Promise<string>;
|
|
95
|
+
getStatus(requestId: string): Promise<EndpointOutput>;
|
|
96
|
+
stream(requestId: string): Promise<EndpointOutput>;
|
|
97
|
+
cancel(requestId: string): Promise<CancelOutput>;
|
|
98
|
+
getHealth(): Promise<HealthCheck>;
|
|
99
|
+
purgeQueue(): Promise<PurgeQueueOutput>;
|
|
100
|
+
}
|
|
101
|
+
declare const _default: (apiKey: string) => {
|
|
102
|
+
endpoint: (endpointId: string) => Endpoint;
|
|
103
|
+
};
|
|
104
|
+
export default _default;
|
|
@@ -0,0 +1,17 @@
|
|
|
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: "Hi, what's your name?",
|
|
14
|
+
},
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
console.log(result)
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import runpodSdk
|
|
1
|
+
import runpodSdk from "../dist/index.js"
|
|
2
2
|
|
|
3
3
|
const { RUNPOD_API_KEY, ENDPOINT_ID } = process.env
|
|
4
4
|
if (!(RUNPOD_API_KEY && ENDPOINT_ID)) {
|
|
5
|
+
console.log("please supply RUNPOD_API_KEY and ENDPOINT_ID as environment variables")
|
|
5
6
|
process.exit()
|
|
6
7
|
}
|
|
7
8
|
//OOP
|
|
@@ -39,12 +40,3 @@ console.log(await endpoint.getHealth())
|
|
|
39
40
|
console.log("runSync")
|
|
40
41
|
const result = await endpoint.runSync(request)
|
|
41
42
|
console.log(result)
|
|
42
|
-
//functional
|
|
43
|
-
// const run = runSync(RUNPOD_API_KEY, ENDPOINT_ID)
|
|
44
|
-
// const res = await run({
|
|
45
|
-
// input: {
|
|
46
|
-
// prompt: "a photo of a horse the size of a Boeing 787",
|
|
47
|
-
// },
|
|
48
|
-
// })
|
|
49
|
-
|
|
50
|
-
// console.log(res)
|
package/package.json
CHANGED