Skip to content

Commit 88e8283

Browse files
committed
fix: Added logs
1 parent fbb9092 commit 88e8283

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

examples/studio/conversational-rag/rag-engine.ts

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,33 +27,41 @@ async function waitForFileProcessing(
2727
async function uploadGetUpdateDelete(fileInput, path) {
2828
const client = new AI21({ apiKey: process.env.AI21_API_KEY });
2929
try {
30-
console.log(`Uploading file with id ${fileInput}`);
30+
console.log(`Starting upload for file:`, typeof fileInput);
3131
const uploadFileResponse: UploadFileResponse = await client.files.create({
3232
file: fileInput,
3333
path: path,
3434
});
35-
console.log(`Uploaded file with id ${uploadFileResponse}`);
35+
console.log(`✓ Upload completed. File ID: ${uploadFileResponse.fileId}`);
3636

37+
console.log('Waiting for file processing...');
3738
let file: FileResponse = await waitForFileProcessing(client, uploadFileResponse.fileId);
38-
console.log(file);
39+
console.log(`✓ File processing completed with status: ${file.status}`);
3940

4041
if (file.status === 'PROCESSED') {
41-
console.log('Now updating the file labels and publicUrl...');
42+
console.log('Starting file update...');
4243
await client.files.update({
4344
fileId: uploadFileResponse.fileId,
4445
labels: ['test99'],
4546
publicUrl: 'https://www.miri.com',
4647
});
4748
file = await client.files.get(uploadFileResponse.fileId);
48-
console.log(file);
49+
console.log('✓ File update completed');
4950
} else {
50-
console.log(`File did not processed well, ended with status ${file.status}`);
51+
console.log(`⚠ File processing failed with status ${file.status}`);
52+
return; // Exit early if processing failed
5153
}
5254

53-
console.log('Now deleting the file');
55+
console.log('Starting file deletion...');
5456
await client.files.delete(uploadFileResponse.fileId);
57+
console.log('✓ File deletion completed');
58+
59+
// Add buffer time between operations
60+
await sleep(2000);
61+
5562
} catch (error) {
56-
console.error('Error:', error);
63+
console.error('❌ Error in uploadGetUpdateDelete:', error);
64+
throw error;
5765
}
5866
}
5967

@@ -71,22 +79,29 @@ if (isBrowser) {
7179
/* Run all operations sequentially */
7280
(async () => {
7381
try {
82+
console.log('=== Starting first operation ===');
7483
// First operation - upload file from path
7584
const filePath = path.join(process.cwd(), 'examples/studio/conversational-rag/files', 'meerkat.txt');
7685
await uploadGetUpdateDelete(filePath, Date.now().toString());
86+
console.log('=== First operation completed ===\n');
87+
await sleep(2000);
7788

89+
console.log('=== Starting second operation ===');
7890
// Second operation - upload file from File instance
7991
const fileContent = Buffer.from(
8092
'Opossums are members of the marsupial order Didelphimorphia endemic to the Americas.',
8193
);
8294
const dummyFile = new File([fileContent], 'example.txt', { type: 'text/plain' });
83-
console.log('Running file upload in Node environment');
8495
await uploadGetUpdateDelete(dummyFile, Date.now().toString());
96+
console.log('=== Second operation completed ===\n');
97+
await sleep(2000);
8598

86-
// Finally, list the files
99+
console.log('=== Starting file listing ===');
87100
await listFiles();
101+
console.log('=== File listing completed ===');
88102
} catch (error) {
89-
console.error(error);
103+
console.error('❌ Main execution error:', error);
104+
process.exit(1); // Exit with error code if something fails
90105
}
91106
})();
92107
}

0 commit comments

Comments
 (0)