Skip to content

Commit e251c1b

Browse files
committed
fix: Run sync
1 parent 5888d67 commit e251c1b

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

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

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,33 @@ async function uploadGetUpdateDelete(fileInput, path) {
6060
async function listFiles() {
6161
const client = new AI21({ apiKey: process.env.AI21_API_KEY });
6262
const files = await client.files.list({ limit: 4 });
63-
console.log(files);
63+
console.log(`Listed files: ${files}`);
6464
}
6565

6666
const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
6767

6868
if (isBrowser) {
6969
console.log('Cannot run upload examples in Browser environment');
7070
} else {
71-
/* Simulate file upload passing a path to file */
72-
const filePath = path.join(process.cwd(), 'examples/studio/conversational-rag/files', 'meerkat.txt'); // Use process.cwd() to get the current working directory
71+
/* Run all operations sequentially */
72+
(async () => {
73+
try {
74+
// First operation - upload file from path
75+
const filePath = path.join(process.cwd(), 'examples/studio/conversational-rag/files', 'meerkat.txt');
76+
await uploadGetUpdateDelete(filePath, Date.now().toString());
7377

74-
uploadGetUpdateDelete(filePath, Date.now().toString()).catch(console.error);
78+
// Second operation - upload file from File instance
79+
const fileContent = Buffer.from(
80+
'Opossums are members of the marsupial order Didelphimorphia endemic to the Americas.',
81+
);
82+
const dummyFile = new File([fileContent], 'example.txt', { type: 'text/plain' });
83+
console.log('Running file upload in Node environment');
84+
await uploadGetUpdateDelete(dummyFile, Date.now().toString());
7585

76-
/* Simulate file upload passing File instance */
77-
const fileContent = Buffer.from(
78-
'Opossums are members of the marsupial order Didelphimorphia endemic to the Americas.',
79-
);
80-
const dummyFile = new File([fileContent], 'example.txt', { type: 'text/plain' });
81-
console.log('Running file upload in Node environment');
82-
uploadGetUpdateDelete(dummyFile, Date.now().toString()).catch(console.error);
83-
listFiles().catch(console.error);
86+
// Finally, list the files
87+
await listFiles();
88+
} catch (error) {
89+
console.error(error);
90+
}
91+
})();
8492
}

0 commit comments

Comments
 (0)