@pipedream/openai 0.4.1 → 0.4.3

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.
@@ -2,7 +2,7 @@ import openai from "../../openai.app.mjs";
2
2
 
3
3
  export default {
4
4
  name: "Create Image",
5
- version: "0.1.10",
5
+ version: "0.1.11",
6
6
  key: "openai-create-image",
7
7
  description: "Creates an image given a prompt. returns a URL to the image. [See docs here](https://platform.openai.com/docs/api-reference/images)",
8
8
  type: "action",
@@ -48,7 +48,7 @@ export default {
48
48
  },
49
49
  {
50
50
  label: "HD",
51
- value: "HD",
51
+ value: "hd",
52
52
  },
53
53
  ],
54
54
  default: "standard",
@@ -17,13 +17,14 @@ import constants from "../common/constants.mjs";
17
17
  import lang from "../common/lang.mjs";
18
18
 
19
19
  const COMMON_AUDIO_FORMATS_TEXT = "Your audio file must be in one of these formats: mp3, mp4, mpeg, mpga, m4a, wav, or webm.";
20
+ const CHUNK_SIZE_MB = 20;
20
21
 
21
22
  const execAsync = promisify(exec);
22
23
  const pipelineAsync = promisify(stream.pipeline);
23
24
 
24
25
  export default {
25
26
  name: "Create Transcription",
26
- version: "0.1.4",
27
+ version: "0.1.6",
27
28
  key: "openai-create-transcription",
28
29
  description: "Transcribes audio into the input language. [See docs here](https://platform.openai.com/docs/api-reference/audio/create).",
29
30
  type: "action",
@@ -104,6 +105,18 @@ export default {
104
105
  form.append("file", readStream);
105
106
  return form;
106
107
  },
108
+ async splitLargeChunks(files, outputDir) {
109
+ for (const file of files) {
110
+ if (fs.statSync(`${outputDir}/${file}`).size / (1024 * 1024) > CHUNK_SIZE_MB) {
111
+ await this.chunkFile({
112
+ file: `${outputDir}/${file}`,
113
+ outputDir,
114
+ index: file.slice(6, 9),
115
+ });
116
+ await execAsync(`rm -f "${outputDir}/${file}"`);
117
+ }
118
+ }
119
+ },
107
120
  async chunkFileAndTranscribe({
108
121
  file, $,
109
122
  }) {
@@ -116,22 +129,31 @@ export default {
116
129
  outputDir,
117
130
  });
118
131
 
119
- const files = await fs.promises.readdir(outputDir);
132
+ let files = await fs.promises.readdir(outputDir);
133
+ // ffmpeg will sometimes return chunks larger than the allowed size,
134
+ // so we need to identify large chunks and break them down further
135
+ await this.splitLargeChunks(files, outputDir);
136
+ files = await fs.promises.readdir(outputDir);
120
137
 
121
- return await this.transcribeFiles({
138
+ return this.transcribeFiles({
122
139
  files,
123
140
  outputDir,
124
141
  $,
125
142
  });
126
143
  },
127
144
  async chunkFile({
128
- file, outputDir,
145
+ file, outputDir, index,
129
146
  }) {
130
147
  const ffmpegPath = ffmpegInstaller.path;
131
148
  const ext = extname(file);
132
149
 
133
150
  const fileSizeInMB = fs.statSync(file).size / (1024 * 1024);
134
- const numberOfChunks = Math.ceil(fileSizeInMB / 24);
151
+ // We're limited to 26MB per request. Because of how ffmpeg splits files,
152
+ // we need to be conservative in the number of chunks we create
153
+ const conservativeChunkSizeMB = CHUNK_SIZE_MB;
154
+ const numberOfChunks = !index
155
+ ? Math.ceil(fileSizeInMB / conservativeChunkSizeMB)
156
+ : 2;
135
157
 
136
158
  if (numberOfChunks === 1) {
137
159
  await execAsync(`cp "${file}" "${outputDir}/chunk-000${ext}"`);
@@ -149,7 +171,9 @@ export default {
149
171
  const totalSeconds = (hours * 60 * 60) + (minutes * 60) + seconds;
150
172
  const segmentTime = Math.ceil(totalSeconds / numberOfChunks);
151
173
 
152
- const command = `${ffmpegPath} -i "${file}" -f segment -segment_time ${segmentTime} -c copy "${outputDir}/chunk-%03d${ext}"`;
174
+ const command = `${ffmpegPath} -i "${file}" -f segment -segment_time ${segmentTime} -c copy "${outputDir}/chunk-${index
175
+ ? `${index}-`
176
+ : ""}%03d${ext}"`;
153
177
  await execAsync(command);
154
178
  },
155
179
  transcribeFiles({
@@ -191,14 +215,14 @@ export default {
191
215
  } = this;
192
216
 
193
217
  if (!url && !path) {
194
- throw new Error("Must specify either File URL or File Path");
218
+ throw new ConfigurationError("Must specify either File URL or File Path");
195
219
  }
196
220
 
197
221
  let file;
198
222
 
199
223
  if (path) {
200
224
  if (!fs.existsSync(path)) {
201
- throw new Error(`${path} does not exist`);
225
+ throw new ConfigurationError(`${path} does not exist`);
202
226
  }
203
227
 
204
228
  file = path;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/openai",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
4
4
  "description": "Pipedream OpenAI Components",
5
5
  "main": "openai.app.mjs",
6
6
  "keywords": [