|
1 |
| -import { AI21, FileResponse, UploadFileResponse, isBrowser } from 'ai21'; |
| 1 | +import { AI21, FileResponse, UploadFileResponse } from 'ai21'; |
2 | 2 | import path from 'path';
|
3 | 3 |
|
4 | 4 | function sleep(ms) {
|
@@ -31,7 +31,7 @@ async function uploadGetUpdateDelete(fileInput, path) {
|
31 | 31 | file: fileInput,
|
32 | 32 | path: path,
|
33 | 33 | });
|
34 |
| - console.log(uploadFileResponse); |
| 34 | + console.log(`Uploaded file with id ${uploadFileResponse}`); |
35 | 35 |
|
36 | 36 | let file: FileResponse = await waitForFileProcessing(client, uploadFileResponse.fileId);
|
37 | 37 | console.log(file);
|
@@ -62,20 +62,21 @@ async function listFiles() {
|
62 | 62 | console.log(files);
|
63 | 63 | }
|
64 | 64 |
|
65 |
| -/* Simulate file upload passing a path to file */ |
66 |
| -const filePath = path.join(process.cwd(), 'examples/studio/conversational-rag/files', 'meerkat.txt'); // Use process.cwd() to get the current working directory |
67 |
| - |
68 |
| -uploadGetUpdateDelete(filePath, Date.now().toString()).catch(console.error); |
69 |
| - |
70 |
| -/* Simulate file upload passing File instance */ |
71 |
| -const fileContent = Buffer.from( |
72 |
| - 'Opossums are members of the marsupial order Didelphimorphia endemic to the Americas.', |
73 |
| -); |
74 |
| -const dummyFile = new File([fileContent], 'example.txt', { type: 'text/plain' }); |
| 65 | +const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined'; |
75 | 66 |
|
76 | 67 | if (isBrowser) {
|
77 | 68 | console.log('Cannot run upload examples in Browser environment');
|
78 | 69 | } else {
|
| 70 | + /* Simulate file upload passing a path to file */ |
| 71 | + const filePath = path.join(process.cwd(), 'examples/studio/conversational-rag/files', 'meerkat.txt'); // Use process.cwd() to get the current working directory |
| 72 | + |
| 73 | + uploadGetUpdateDelete(filePath, Date.now().toString()).catch(console.error); |
| 74 | + |
| 75 | + /* Simulate file upload passing File instance */ |
| 76 | + const fileContent = Buffer.from( |
| 77 | + 'Opossums are members of the marsupial order Didelphimorphia endemic to the Americas.', |
| 78 | + ); |
| 79 | + const dummyFile = new File([fileContent], 'example.txt', { type: 'text/plain' }); |
79 | 80 | console.log('Running file upload in Node environment');
|
80 | 81 | uploadGetUpdateDelete(dummyFile, Date.now().toString()).catch(console.error);
|
81 | 82 | listFiles().catch(console.error);
|
|
0 commit comments