spice-js 2.6.49 → 2.6.51
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/build/nova/Ai.js +17 -17
- package/package.json +1 -1
- package/src/nova/Ai.js +16 -13
package/build/nova/Ai.js
CHANGED
|
@@ -66,10 +66,13 @@ class AI {
|
|
|
66
66
|
_fs.default.mkdirSync(outputDir, {
|
|
67
67
|
recursive: true
|
|
68
68
|
});
|
|
69
|
-
}
|
|
69
|
+
}
|
|
70
70
|
|
|
71
|
+
var timestamp = new Date().toISOString().replace(/[:.-]/g, "");
|
|
72
|
+
var randomString = crypto.randomBytes(4).toString("hex");
|
|
73
|
+
var uniqueDirName = "file_" + timestamp + "_" + randomString; // Create a temporary file to store the input
|
|
71
74
|
|
|
72
|
-
var tempFilePath = path.join(outputDir,
|
|
75
|
+
var tempFilePath = path.join(outputDir, uniqueDirName); // Check if fileData is a buffer or a stream
|
|
73
76
|
|
|
74
77
|
if (Buffer.isBuffer(fileData)) {
|
|
75
78
|
// It's a buffer, write it directly to the temp file
|
|
@@ -85,9 +88,10 @@ class AI {
|
|
|
85
88
|
|
|
86
89
|
if (_lodash.default.includes(supportedFileTypes, fileType)) {
|
|
87
90
|
// If it's a JPEG or PNG, just move it to the output directory
|
|
88
|
-
var
|
|
91
|
+
var _timestamp = new Date().toISOString().replace(/[:.-]/g, "");
|
|
92
|
+
|
|
89
93
|
var extension = fileType === "jpeg" ? "jpg" : fileType;
|
|
90
|
-
var outputPath = path.join(outputDir,
|
|
94
|
+
var outputPath = path.join(outputDir, _timestamp + "." + extension);
|
|
91
95
|
|
|
92
96
|
_fs.default.renameSync(tempFilePath, outputPath);
|
|
93
97
|
|
|
@@ -235,18 +239,14 @@ class AI {
|
|
|
235
239
|
|
|
236
240
|
var outputDir = _this3.createUniqueDirectory();
|
|
237
241
|
|
|
238
|
-
|
|
239
|
-
/*#__PURE__*/
|
|
240
|
-
function () {
|
|
241
|
-
var _ref = _asyncToGenerator(function* (fileData) {
|
|
242
|
-
var imagePaths = yield _this3.extractOrStoreFile(fileData, outputDir, types);
|
|
243
|
-
return imagePaths;
|
|
244
|
-
});
|
|
242
|
+
var results = [];
|
|
245
243
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
}
|
|
244
|
+
for (var fileData of files) {
|
|
245
|
+
var imagePaths = yield _this3.extractOrStoreFile(fileData, outputDir, types);
|
|
246
|
+
results.push(imagePaths);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return results.flat();
|
|
250
250
|
})();
|
|
251
251
|
}
|
|
252
252
|
|
|
@@ -259,7 +259,7 @@ class AI {
|
|
|
259
259
|
return provider.getSupportedTypes();
|
|
260
260
|
}
|
|
261
261
|
|
|
262
|
-
prompt(prompt,
|
|
262
|
+
prompt(prompt, _ref, options) {
|
|
263
263
|
var _this4 = this;
|
|
264
264
|
|
|
265
265
|
return _asyncToGenerator(function* () {
|
|
@@ -267,7 +267,7 @@ class AI {
|
|
|
267
267
|
files,
|
|
268
268
|
system_message,
|
|
269
269
|
prompt_options
|
|
270
|
-
} =
|
|
270
|
+
} = _ref;
|
|
271
271
|
var context_files = yield _this4.processFiles(files);
|
|
272
272
|
|
|
273
273
|
try {
|
package/package.json
CHANGED
package/src/nova/Ai.js
CHANGED
|
@@ -39,8 +39,12 @@ export default class AI {
|
|
|
39
39
|
fs.mkdirSync(outputDir, { recursive: true });
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
const timestamp = new Date().toISOString().replace(/[:.-]/g, "");
|
|
43
|
+
const randomString = crypto.randomBytes(4).toString("hex");
|
|
44
|
+
const uniqueDirName = `file_${timestamp}_${randomString}`;
|
|
45
|
+
|
|
42
46
|
// Create a temporary file to store the input
|
|
43
|
-
const tempFilePath = path.join(outputDir,
|
|
47
|
+
const tempFilePath = path.join(outputDir, uniqueDirName);
|
|
44
48
|
|
|
45
49
|
// Check if fileData is a buffer or a stream
|
|
46
50
|
if (Buffer.isBuffer(fileData)) {
|
|
@@ -201,19 +205,18 @@ export default class AI {
|
|
|
201
205
|
async processFiles(files) {
|
|
202
206
|
let types = this.getSupportedFileTypes();
|
|
203
207
|
const outputDir = this.createUniqueDirectory();
|
|
208
|
+
let results = [];
|
|
209
|
+
|
|
210
|
+
for (const fileData of files) {
|
|
211
|
+
const imagePaths = await this.extractOrStoreFile(
|
|
212
|
+
fileData,
|
|
213
|
+
outputDir,
|
|
214
|
+
types
|
|
215
|
+
);
|
|
216
|
+
results.push(imagePaths);
|
|
217
|
+
}
|
|
204
218
|
|
|
205
|
-
return (
|
|
206
|
-
await Promise.all(
|
|
207
|
-
files.map(async (fileData) => {
|
|
208
|
-
const imagePaths = await this.extractOrStoreFile(
|
|
209
|
-
fileData,
|
|
210
|
-
outputDir,
|
|
211
|
-
types
|
|
212
|
-
);
|
|
213
|
-
return imagePaths;
|
|
214
|
-
})
|
|
215
|
-
)
|
|
216
|
-
).flat();
|
|
219
|
+
return results.flat();
|
|
217
220
|
}
|
|
218
221
|
|
|
219
222
|
getSupportedFileTypes(options) {
|