@pipedream/openai 1.2.0 → 1.2.1
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pipedream/openai",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Pipedream OpenAI Components",
|
|
5
5
|
"main": "openai.app.mjs",
|
|
6
6
|
"keywords": [
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@pipedream/platform": "^3.1.0",
|
|
18
18
|
"bottleneck": "^2.19.5",
|
|
19
|
+
"file-type": "^21.0.0",
|
|
19
20
|
"form-data": "^4.0.0",
|
|
20
21
|
"got": "^12.6.0",
|
|
21
22
|
"openai": "^4.77.0"
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import common from "../common/common.mjs";
|
|
2
|
+
import { Readable } from "stream";
|
|
3
|
+
import { fileTypeFromBuffer } from "file-type";
|
|
2
4
|
import sampleEmit from "./test-event.mjs";
|
|
3
5
|
|
|
4
6
|
export default {
|
|
@@ -6,7 +8,7 @@ export default {
|
|
|
6
8
|
key: "openai-new-file-created",
|
|
7
9
|
name: "New File Created",
|
|
8
10
|
description: "Emit new event when a new file is created in OpenAI. [See the documentation](https://platform.openai.com/docs/api-reference/files/list)",
|
|
9
|
-
version: "0.0
|
|
11
|
+
version: "0.1.0",
|
|
10
12
|
type: "source",
|
|
11
13
|
dedupe: "unique",
|
|
12
14
|
props: {
|
|
@@ -19,6 +21,18 @@ export default {
|
|
|
19
21
|
description: "If specified, events will only be emitted for files with the specified purpose.",
|
|
20
22
|
optional: true,
|
|
21
23
|
},
|
|
24
|
+
includeLink: {
|
|
25
|
+
label: "Include Link",
|
|
26
|
+
type: "boolean",
|
|
27
|
+
description: "Upload file to your File Stash and emit temporary download link to the file. See [the docs](https://pipedream.com/docs/connect/components/files) to learn more about working with files in Pipedream.",
|
|
28
|
+
default: false,
|
|
29
|
+
optional: true,
|
|
30
|
+
},
|
|
31
|
+
dir: {
|
|
32
|
+
type: "dir",
|
|
33
|
+
accessMode: "write",
|
|
34
|
+
optional: true,
|
|
35
|
+
},
|
|
22
36
|
},
|
|
23
37
|
methods: {
|
|
24
38
|
...common.methods,
|
|
@@ -34,6 +48,44 @@ export default {
|
|
|
34
48
|
ts: item.created_at * 1000,
|
|
35
49
|
};
|
|
36
50
|
},
|
|
51
|
+
async stashFile(item) {
|
|
52
|
+
const response = await this.openai.retrieveFileContent({
|
|
53
|
+
file_id: item.id,
|
|
54
|
+
responseType: "arraybuffer",
|
|
55
|
+
});
|
|
56
|
+
const buffer = Buffer.from(response);
|
|
57
|
+
const filepath = `${item.id}/${item.filename}`;
|
|
58
|
+
const type = await fileTypeFromBuffer(buffer);
|
|
59
|
+
const file = await this.dir.open(filepath).fromReadableStream(
|
|
60
|
+
Readable.from(buffer),
|
|
61
|
+
type?.mime,
|
|
62
|
+
buffer.length,
|
|
63
|
+
);
|
|
64
|
+
return await file.withoutPutUrl().withGetUrl();
|
|
65
|
+
},
|
|
66
|
+
async getAndProcessItems(maxEvents) {
|
|
67
|
+
const lastCreated = this._getLastCreated();
|
|
68
|
+
const { data } = await this.getData();
|
|
69
|
+
if (!data?.length) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
this._setLastCreated(data[0].created_at);
|
|
73
|
+
const items = data?.filter(({ created_at }) => created_at >= lastCreated).reverse();
|
|
74
|
+
let count = 0;
|
|
75
|
+
for (const item of items) {
|
|
76
|
+
if (!maxEvents || count < maxEvents) {
|
|
77
|
+
if (this.includeLink) {
|
|
78
|
+
try {
|
|
79
|
+
item.file = await this.stashFile(item);
|
|
80
|
+
} catch (error) {
|
|
81
|
+
item.file = `Could not upload file ${item.filename } to File Stash`;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
this.$emit(item, this.getMeta(item));
|
|
85
|
+
count++;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
},
|
|
37
89
|
},
|
|
38
90
|
sampleEmit,
|
|
39
91
|
};
|