@pipedream/openai 0.10.0 → 1.0.0
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/actions/analyze-image-content/analyze-image-content.mjs +12 -14
- package/actions/chat/chat.mjs +14 -9
- package/actions/common/common.mjs +31 -10
- package/actions/create-batch/create-batch.mjs +14 -9
- package/actions/create-transcription/create-transcription.mjs +10 -6
- package/actions/upload-file/upload-file.mjs +10 -6
- package/openai.app.mjs +2 -2
- package/package.json +2 -2
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import openai from "../../openai.app.mjs";
|
|
2
2
|
import common from "../common/common-assistants.mjs";
|
|
3
3
|
import FormData from "form-data";
|
|
4
|
-
import
|
|
4
|
+
import { getFileStreamAndMetadata } from "@pipedream/platform";
|
|
5
5
|
|
|
6
6
|
export default {
|
|
7
7
|
...common,
|
|
8
8
|
key: "openai-analyze-image-content",
|
|
9
9
|
name: "Analyze Image Content",
|
|
10
10
|
description: "Send a message or question about an image and receive a response. [See the documentation](https://platform.openai.com/docs/api-reference/runs/createThreadAndRun)",
|
|
11
|
-
version: "0.
|
|
11
|
+
version: "1.0.0",
|
|
12
12
|
type: "action",
|
|
13
13
|
props: {
|
|
14
14
|
openai,
|
|
@@ -17,12 +17,6 @@ export default {
|
|
|
17
17
|
label: "Message",
|
|
18
18
|
description: "The message or question to send",
|
|
19
19
|
},
|
|
20
|
-
imageUrl: {
|
|
21
|
-
type: "string",
|
|
22
|
-
label: "Image URL",
|
|
23
|
-
description: "The URL of the image to analyze. Must be a supported image types: jpeg, jpg, png, gif, webp",
|
|
24
|
-
optional: true,
|
|
25
|
-
},
|
|
26
20
|
imageFileId: {
|
|
27
21
|
propDefinition: [
|
|
28
22
|
openai,
|
|
@@ -35,8 +29,8 @@ export default {
|
|
|
35
29
|
},
|
|
36
30
|
filePath: {
|
|
37
31
|
type: "string",
|
|
38
|
-
label: "File Path",
|
|
39
|
-
description: "The path to a file in the `/tmp` directory.
|
|
32
|
+
label: "File Path or URL",
|
|
33
|
+
description: "The image to process. Provide either a file URL or a path to a file in the `/tmp` directory (for example, `/tmp/myFile.jpg`). Supported image types: jpeg, jpg, png, gif, webp",
|
|
40
34
|
optional: true,
|
|
41
35
|
},
|
|
42
36
|
},
|
|
@@ -83,11 +77,15 @@ export default {
|
|
|
83
77
|
}
|
|
84
78
|
if (this.filePath) {
|
|
85
79
|
const fileData = new FormData();
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
80
|
+
const {
|
|
81
|
+
stream, metadata,
|
|
82
|
+
} = await getFileStreamAndMetadata(this.filePath);
|
|
89
83
|
fileData.append("purpose", "vision");
|
|
90
|
-
fileData.append("file",
|
|
84
|
+
fileData.append("file", stream, {
|
|
85
|
+
contentType: metadata.contentType,
|
|
86
|
+
knownLength: metadata.size,
|
|
87
|
+
filename: metadata.name,
|
|
88
|
+
});
|
|
91
89
|
|
|
92
90
|
const { id } = await this.openai.uploadFile({
|
|
93
91
|
$,
|
package/actions/chat/chat.mjs
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import openai from "../../openai.app.mjs";
|
|
2
2
|
import common from "../common/common.mjs";
|
|
3
3
|
import constants from "../../common/constants.mjs";
|
|
4
|
-
import { ConfigurationError } from "@pipedream/platform";
|
|
5
4
|
|
|
6
5
|
export default {
|
|
7
6
|
...common,
|
|
8
7
|
name: "Chat",
|
|
9
|
-
version: "0.
|
|
8
|
+
version: "0.3.0",
|
|
10
9
|
key: "openai-chat",
|
|
11
10
|
description: "The Chat API, using the `gpt-3.5-turbo` or `gpt-4` model. [See the documentation](https://platform.openai.com/docs/api-reference/chat)",
|
|
12
11
|
type: "action",
|
|
@@ -44,13 +43,13 @@ export default {
|
|
|
44
43
|
images: {
|
|
45
44
|
label: "Images",
|
|
46
45
|
type: "string[]",
|
|
47
|
-
description: "Provide one or more images to [OpenAI's vision model](https://platform.openai.com/docs/guides/vision).
|
|
46
|
+
description: "Provide one or more images to [OpenAI's vision model](https://platform.openai.com/docs/guides/vision). Each entry should be either a file URL or a path to a file in the `/tmp` directory (for example, `/tmp/myFile.jpg`), or raw base64-encoded image data. Compatible with the `gpt4-vision-preview` model",
|
|
48
47
|
optional: true,
|
|
49
48
|
},
|
|
50
49
|
audio: {
|
|
51
50
|
type: "string",
|
|
52
51
|
label: "Audio",
|
|
53
|
-
description: "Provide
|
|
52
|
+
description: "The audio file to upload. Provide either a file URL or a path to a file in the `/tmp` directory (for example, `/tmp/myFile.mp3`). For use with the `gpt-4o-audio-preview` model. Currently supports `wav` and `mp3` files.",
|
|
54
53
|
optional: true,
|
|
55
54
|
},
|
|
56
55
|
responseFormat: {
|
|
@@ -145,11 +144,7 @@ export default {
|
|
|
145
144
|
},
|
|
146
145
|
},
|
|
147
146
|
async run({ $ }) {
|
|
148
|
-
|
|
149
|
-
throw new ConfigurationError("Use of audio files requires using the `gpt-4o-audio-preview` model.");
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
const args = this._getChatArgs();
|
|
147
|
+
const args = await this._getChatArgs();
|
|
153
148
|
|
|
154
149
|
const response = await this.openai.createChatCompletion({
|
|
155
150
|
$,
|
|
@@ -159,6 +154,16 @@ export default {
|
|
|
159
154
|
},
|
|
160
155
|
});
|
|
161
156
|
|
|
157
|
+
if (this.responseFormat === constants.CHAT_RESPONSE_FORMAT.JSON_SCHEMA.value) {
|
|
158
|
+
for (const choice of response.choices) {
|
|
159
|
+
try {
|
|
160
|
+
choice.message.content = JSON.parse(choice.message.content);
|
|
161
|
+
} catch {
|
|
162
|
+
console.log(`Unable to parse JSON: ${choice.message.content}`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
162
167
|
if (response) {
|
|
163
168
|
$.export("$summary", `Successfully sent chat with id ${response.id}`);
|
|
164
169
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
ConfigurationError, getFileStreamAndMetadata,
|
|
3
|
+
} from "@pipedream/platform";
|
|
2
4
|
import constants from "../../common/constants.mjs";
|
|
3
5
|
import { parse } from "../../common/helpers.mjs";
|
|
4
|
-
import fs from "fs";
|
|
5
6
|
|
|
6
7
|
const CHAT_DOCS_MESSAGE_FORMAT_URL = "https://platform.openai.com/docs/guides/chat/introduction";
|
|
7
8
|
|
|
@@ -80,24 +81,44 @@ export default {
|
|
|
80
81
|
user: this.user,
|
|
81
82
|
};
|
|
82
83
|
},
|
|
83
|
-
_getUserMessageContent() {
|
|
84
|
+
async _getUserMessageContent() {
|
|
84
85
|
let content = [];
|
|
85
86
|
if (this.images) {
|
|
86
87
|
for (const image of this.images) {
|
|
88
|
+
let base64Image = image;
|
|
89
|
+
let imageType = "image/jpeg";
|
|
90
|
+
if (image.startsWith("http") || image.includes("tmp/")) {
|
|
91
|
+
const {
|
|
92
|
+
stream, metadata,
|
|
93
|
+
} = await getFileStreamAndMetadata(image);
|
|
94
|
+
const chunks = [];
|
|
95
|
+
for await (const chunk of stream) {
|
|
96
|
+
chunks.push(chunk);
|
|
97
|
+
}
|
|
98
|
+
base64Image = Buffer.concat(chunks).toString("base64");
|
|
99
|
+
if (metadata.contentType) imageType = metadata.contentType;
|
|
100
|
+
}
|
|
87
101
|
content.push({
|
|
88
102
|
"type": "image_url",
|
|
89
103
|
"image_url": {
|
|
90
|
-
"url":
|
|
104
|
+
"url": base64Image.startsWith("data:")
|
|
105
|
+
? base64Image
|
|
106
|
+
: `data:${imageType};base64,${base64Image}`,
|
|
91
107
|
},
|
|
92
108
|
});
|
|
93
109
|
}
|
|
94
110
|
}
|
|
95
111
|
|
|
96
112
|
if (this.audio) {
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const
|
|
113
|
+
const {
|
|
114
|
+
stream, metadata,
|
|
115
|
+
} = await getFileStreamAndMetadata(this.audio);
|
|
116
|
+
const chunks = [];
|
|
117
|
+
for await (const chunk of stream) {
|
|
118
|
+
chunks.push(chunk);
|
|
119
|
+
}
|
|
120
|
+
const fileContent = Buffer.concat(chunks).toString("base64");
|
|
121
|
+
const extension = metadata.name.split(".").pop();
|
|
101
122
|
content.push({
|
|
102
123
|
type: "input_audio",
|
|
103
124
|
input_audio: {
|
|
@@ -114,7 +135,7 @@ export default {
|
|
|
114
135
|
|
|
115
136
|
return content;
|
|
116
137
|
},
|
|
117
|
-
_getChatArgs() {
|
|
138
|
+
async _getChatArgs() {
|
|
118
139
|
if (this.messages && this.messages.length && !this.userMessage) {
|
|
119
140
|
throw new ConfigurationError(
|
|
120
141
|
`When you provide previous messages, you must provide the next User Message for the assistant to answer. See the OpenAI Chat format docs here: ${CHAT_DOCS_MESSAGE_FORMAT_URL}`,
|
|
@@ -160,7 +181,7 @@ export default {
|
|
|
160
181
|
|
|
161
182
|
messages.push({
|
|
162
183
|
"role": "user",
|
|
163
|
-
"content": this._getUserMessageContent(),
|
|
184
|
+
"content": await this._getUserMessageContent(),
|
|
164
185
|
});
|
|
165
186
|
|
|
166
187
|
const responseFormat = {};
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import openai from "../../openai.app.mjs";
|
|
2
2
|
import constants from "../../common/constants.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
ConfigurationError, getFileStreamAndMetadata,
|
|
5
|
+
} from "@pipedream/platform";
|
|
4
6
|
import FormData from "form-data";
|
|
5
|
-
import fs from "fs";
|
|
6
7
|
|
|
7
8
|
export default {
|
|
8
9
|
key: "openai-create-batch",
|
|
9
10
|
name: "Create Batch",
|
|
10
11
|
description: "Creates and executes a batch from an uploaded file of requests. [See the documentation](https://platform.openai.com/docs/api-reference/batch/create)",
|
|
11
|
-
version: "0.0
|
|
12
|
+
version: "0.1.0",
|
|
12
13
|
type: "action",
|
|
13
14
|
props: {
|
|
14
15
|
openai,
|
|
@@ -30,8 +31,8 @@ export default {
|
|
|
30
31
|
},
|
|
31
32
|
filePath: {
|
|
32
33
|
type: "string",
|
|
33
|
-
label: "File Path",
|
|
34
|
-
description: "The path to a
|
|
34
|
+
label: "File Path or URL",
|
|
35
|
+
description: "The .jsonl file to process. Provide either a file URL or a path to a file in the `/tmp` directory (for example, `/tmp/myFile.jpg`)",
|
|
35
36
|
optional: true,
|
|
36
37
|
},
|
|
37
38
|
metadata: {
|
|
@@ -49,11 +50,15 @@ export default {
|
|
|
49
50
|
let fileId = this.fileId;
|
|
50
51
|
if (this.filePath) {
|
|
51
52
|
const fileData = new FormData();
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
const {
|
|
54
|
+
stream, metadata,
|
|
55
|
+
} = await getFileStreamAndMetadata(this.filePath);
|
|
55
56
|
fileData.append("purpose", "batch");
|
|
56
|
-
fileData.append("file",
|
|
57
|
+
fileData.append("file", stream, {
|
|
58
|
+
contentType: metadata.contentType,
|
|
59
|
+
knownLength: metadata.size,
|
|
60
|
+
filename: metadata.name,
|
|
61
|
+
});
|
|
57
62
|
|
|
58
63
|
const { id } = await this.openai.uploadFile({
|
|
59
64
|
$,
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import { getFileStreamAndMetadata } from "@pipedream/platform";
|
|
1
2
|
import openai from "../../openai.app.mjs";
|
|
2
3
|
import FormData from "form-data";
|
|
3
|
-
import fs from "fs";
|
|
4
4
|
|
|
5
5
|
export default {
|
|
6
6
|
key: "openai-create-transcription",
|
|
7
7
|
name: "Create Transcription",
|
|
8
8
|
description: "Transcribes audio into the input language. [See the documentation](https://platform.openai.com/docs/api-reference/audio/createTranscription)",
|
|
9
|
-
version: "0.
|
|
9
|
+
version: "0.3.0",
|
|
10
10
|
type: "action",
|
|
11
11
|
props: {
|
|
12
12
|
openai,
|
|
@@ -90,11 +90,15 @@ export default {
|
|
|
90
90
|
} = this;
|
|
91
91
|
|
|
92
92
|
const data = new FormData();
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
const {
|
|
94
|
+
stream, metadata,
|
|
95
|
+
} = await getFileStreamAndMetadata(file);
|
|
96
96
|
|
|
97
|
-
data.append("file",
|
|
97
|
+
data.append("file", stream, {
|
|
98
|
+
contentType: metadata.contentType,
|
|
99
|
+
knownLength: metadata.size,
|
|
100
|
+
filename: metadata.name,
|
|
101
|
+
});
|
|
98
102
|
|
|
99
103
|
for (const [
|
|
100
104
|
key,
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import FormData from "form-data";
|
|
2
|
-
import fs from "fs";
|
|
3
2
|
import openai from "../../openai.app.mjs";
|
|
3
|
+
import { getFileStreamAndMetadata } from "@pipedream/platform";
|
|
4
4
|
|
|
5
5
|
export default {
|
|
6
6
|
key: "openai-upload-file",
|
|
7
7
|
name: "Upload File",
|
|
8
8
|
description: "Upload a file that can be used across various endpoints/features. The size of individual files can be a maximum of 512mb. [See the documentation](https://platform.openai.com/docs/api-reference/files/create)",
|
|
9
|
-
version: "0.0
|
|
9
|
+
version: "0.1.0",
|
|
10
10
|
type: "action",
|
|
11
11
|
props: {
|
|
12
12
|
openai,
|
|
@@ -28,11 +28,15 @@ export default {
|
|
|
28
28
|
file, purpose,
|
|
29
29
|
} = this;
|
|
30
30
|
const data = new FormData();
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
const {
|
|
32
|
+
stream, metadata,
|
|
33
|
+
} = await getFileStreamAndMetadata(file);
|
|
34
34
|
data.append("purpose", purpose);
|
|
35
|
-
data.append("file",
|
|
35
|
+
data.append("file", stream, {
|
|
36
|
+
contentType: metadata.contentType,
|
|
37
|
+
knownLength: metadata.size,
|
|
38
|
+
filename: metadata.name,
|
|
39
|
+
});
|
|
36
40
|
|
|
37
41
|
const response = await this.openai.uploadFile({
|
|
38
42
|
$,
|
package/openai.app.mjs
CHANGED
|
@@ -255,8 +255,8 @@ export default {
|
|
|
255
255
|
},
|
|
256
256
|
file: {
|
|
257
257
|
type: "string",
|
|
258
|
-
label: "File",
|
|
259
|
-
description: "The path to a file in the `/tmp` directory
|
|
258
|
+
label: "File Path or URL",
|
|
259
|
+
description: "The file to process. Provide either a file URL or a path to a file in the `/tmp` directory (for example, `/tmp/myFile.txt`). See the [Assistants Tools guide](https://platform.openai.com/docs/assistants/tools) to learn more about the types of files supported. The Fine-tuning API only supports `.jsonl` files.",
|
|
260
260
|
},
|
|
261
261
|
purpose: {
|
|
262
262
|
type: "string",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pipedream/openai",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Pipedream OpenAI Components",
|
|
5
5
|
"main": "openai.app.mjs",
|
|
6
6
|
"keywords": [
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"access": "public"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@pipedream/platform": "^3.0
|
|
17
|
+
"@pipedream/platform": "^3.1.0",
|
|
18
18
|
"@pipedream/types": "^0.1.4",
|
|
19
19
|
"axios": "^1.6.2",
|
|
20
20
|
"bottleneck": "^2.19.5",
|