@pipedream/openai 0.1.5 → 0.1.7

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.
@@ -1,4 +1,5 @@
1
1
  import axios from "axios";
2
+ import Bottleneck from "bottleneck";
2
3
  import fs from "fs";
3
4
  import {
4
5
  join, extname,
@@ -21,7 +22,7 @@ const pipelineAsync = promisify(stream.pipeline);
21
22
 
22
23
  export default {
23
24
  name: "Create Transcription",
24
- version: "0.0.3",
25
+ version: "0.0.6",
25
26
  key: "openai-create-transcription",
26
27
  description: "Transcribes audio into the input language. [See docs here](https://platform.openai.com/docs/api-reference/audio/create).",
27
28
  type: "action",
@@ -107,8 +108,8 @@ export default {
107
108
  file, $,
108
109
  }) {
109
110
  const outputDir = join("/tmp", "chunks");
110
- await execAsync(`mkdir -p ${outputDir}`);
111
- await execAsync(`rm -f ${outputDir}/*`);
111
+ await execAsync(`mkdir -p "${outputDir}"`);
112
+ await execAsync(`rm -f "${outputDir}/*"`);
112
113
 
113
114
  await this.chunkFile({
114
115
  file,
@@ -136,11 +137,11 @@ export default {
136
137
  const numberOfChunks = Math.ceil(fileSizeInMB / 24);
137
138
 
138
139
  if (numberOfChunks === 1) {
139
- await execAsync(`cp ${file} ${outputDir}/chunk-000${ext}`);
140
+ await execAsync(`cp "${file}" "${outputDir}/chunk-000${ext}"`);
140
141
  return;
141
142
  }
142
143
 
143
- const { stdout } = await execAsync(`${ffmpegPath} -i ${file} 2>&1 | grep "Duration"`);
144
+ const { stdout } = await execAsync(`${ffmpegPath} -i "${file}" 2>&1 | grep "Duration"`);
144
145
  const duration = stdout.match(/\d{2}:\d{2}:\d{2}\.\d{2}/s)[0];
145
146
  const [
146
147
  hours,
@@ -151,17 +152,24 @@ export default {
151
152
  const totalSeconds = (hours * 60 * 60) + (minutes * 60) + seconds;
152
153
  const segmentTime = Math.ceil(totalSeconds / numberOfChunks);
153
154
 
154
- const command = `${ffmpegPath} -i ${file} -f segment -segment_time ${segmentTime} -c copy ${outputDir}/chunk-%03d${ext}`;
155
+ const command = `${ffmpegPath} -i "${file}" -f segment -segment_time ${segmentTime} -c copy "${outputDir}/chunk-%03d${ext}"`;
155
156
  await execAsync(command);
156
157
  },
157
158
  async transcribeFiles({
158
159
  files, outputDir, $,
159
160
  }) {
160
- const transcriptions = await Promise.all(files.map((file) => this.transcribe({
161
- file,
162
- outputDir,
163
- $,
164
- })));
161
+ const limiter = new Bottleneck({
162
+ maxConcurrent: 1,
163
+ minTime: 1000 / 59,
164
+ });
165
+
166
+ const transcriptions = await Promise.all(files.map((file) => {
167
+ return limiter.schedule(() => this.transcribe({
168
+ file,
169
+ outputDir,
170
+ $,
171
+ }));
172
+ }));
165
173
  return transcriptions.join(" ");
166
174
  },
167
175
  async transcribe({
@@ -194,6 +202,7 @@ export default {
194
202
  if (!fs.existsSync(path)) {
195
203
  throw new Error(`${path} does not exist`);
196
204
  }
205
+
197
206
  file = path;
198
207
  } else if (url) {
199
208
  const ext = extname(url);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/openai",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "Pipedream OpenAI Components",
5
5
  "main": "app/openai.app.mjs",
6
6
  "keywords": [