Skip to content

Commit 4e7f794

Browse files
committed
fix: Added logs of env
1 parent 9de0844 commit 4e7f794

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

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

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { AI21, FileResponse, UploadFileResponse } from 'ai21';
22
import path from 'path';
3+
import fs from 'fs';
34

45
function sleep(ms) {
56
return new Promise((resolve) => setTimeout(resolve, ms));
@@ -72,6 +73,23 @@ async function listFiles() {
7273

7374
const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
7475

76+
const createNodeFile = (content: Buffer, filename: string, type: string) => {
77+
if (process.platform === 'linux') {
78+
console.log('Running on Linux (GitHub Actions)');
79+
// Special handling for Linux (GitHub Actions)
80+
return {
81+
name: filename,
82+
type: type,
83+
buffer: content,
84+
[Symbol.toStringTag]: 'File'
85+
};
86+
} else {
87+
console.log('Running on other platforms');
88+
// Regular handling for other platforms
89+
return new File([content], filename, { type });
90+
}
91+
};
92+
7593
if (isBrowser) {
7694
console.log('Cannot run upload examples in Browser environment');
7795
} else {
@@ -89,7 +107,10 @@ if (isBrowser) {
89107
try {
90108
console.log('=== Starting first operation ===');
91109
// First operation - upload file from path
92-
const filePath = path.join(process.cwd(), 'examples/studio/conversational-rag/files', 'meerkat.txt');
110+
const filePath = path.resolve(process.cwd(), 'examples/studio/conversational-rag/files', 'meerkat.txt');
111+
if (!fs.existsSync(filePath)) {
112+
throw new Error(`File not found: ${filePath}`);
113+
}
93114
await uploadGetUpdateDelete(filePath, Date.now().toString());
94115
console.log('=== First operation completed ===\n');
95116
await sleep(2000);
@@ -99,7 +120,7 @@ if (isBrowser) {
99120
const fileContent = Buffer.from(
100121
'Opossums are members of the marsupial order Didelphimorphia endemic to the Americas.',
101122
);
102-
const dummyFile = new File([fileContent], 'example.txt', { type: 'text/plain' });
123+
const dummyFile = createNodeFile(fileContent, 'example.txt', 'text/plain');
103124
await uploadGetUpdateDelete(dummyFile, Date.now().toString());
104125
console.log('=== Second operation completed ===\n');
105126
await sleep(2000);

0 commit comments

Comments
 (0)