-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paths3-test.mjs
41 lines (35 loc) · 1.1 KB
/
s3-test.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import {GetObjectCommand, S3Client} from '@aws-sdk/client-s3';
import pkg from 'papaparse';
const {parse} = pkg;
const client = new S3Client({
maxAttempts: 3
});
const command = new GetObjectCommand({
Bucket: 'sommelier-ai',
Key: 'wine_tasting_notes_embeddings__curie_combined.csv'
});
console.log('GETTING OBJECT');
const embeddingsObject = await client.send(command);
console.log('GOT OBJECT');
if(!embeddingsObject?.Body) {
console.log('NO BODY')
}
console.log('PARSED OBJECT');
const streamToString = (stream) => new Promise((resolve, reject) => {
const chunks = [];
stream.on('data', (chunk) => chunks.push(chunk));
stream.on('error', reject);
stream.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')));
});
const embeddingsCsv = await streamToString(embeddingsObject.Body);
// console.log(embeddingsCsv);
console.log('GOT EMBEDDINGS CSV');
const data = parse(embeddingsCsv, {
header: true,
transform: (value, column) => {
if(column === '0') return value;
return JSON.parse(value);
}
});
console.log('GOT EMBEDDINGS DATA');
console.log(data);