Skip to content

Commit e6a13cf

Browse files
committed
refactor: update OpenAI import and enhance error handling for file streams
1 parent 2653bd9 commit e6a13cf

File tree

4 files changed

+26
-14
lines changed

4 files changed

+26
-14
lines changed

i18n/initializers/initialize.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import fs from "fs";
2-
import OpenAI from "openai/index.mjs";
2+
import OpenAI from "openai";
33
import path, { dirname } from "path";
4+
import Stream from "stream";
45
import { fileURLToPath } from "url";
56

67
// Get the directory name of the current module
@@ -24,7 +25,15 @@ export default async function createAssistant(langCode: string, language: string
2425
});
2526

2627
const fileStreams = [path.join(__dirname, "../ai_files", langCode, "dictionary.txt")].map(
27-
path => fs.createReadStream(path)
28+
filePath => {
29+
const stream = fs.createReadStream(filePath);
30+
31+
stream.on('error', err => {
32+
throw new Error(`Failed to read dictionary file at ${filePath}: ${err.message}`)
33+
})
34+
35+
return stream;
36+
}
2837
);
2938

3039
// Create a vector store including our two files.

i18n/package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

i18n/package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010
"url": "https://github.com/coder114514"
1111
}
1212
],
13+
"dependencies": {
14+
"sicp": "^1.1.4",
15+
"openai": "^4.96.2",
16+
"sax": "^1.4.1",
17+
"dotenv": "^16.5.0"
18+
},
1319
"devDependencies": {
14-
"@types/node": "^22.14.1",
15-
"dotenv": "^16.4.7",
16-
"openai": "^4.81.0",
17-
"sax": "^1.4.1"
20+
"@types/node": "^22.15.3"
1821
}
1922
}

i18n/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
"@types/node" "*"
1111
form-data "^4.0.0"
1212

13-
"@types/node@*", "@types/node@^22.14.1":
14-
version "22.14.1"
15-
resolved "https://registry.npmjs.org/@types/node/-/node-22.14.1.tgz"
16-
integrity sha512-u0HuPQwe/dHrItgHHpmw3N2fYCR6x4ivMNbPHRkBVP4CvN+kiRrKHWk3i8tXiO/joPwXLMYvF9TTF0eqgHIuOw==
13+
"@types/node@*", "@types/node@^22.15.3":
14+
version "22.15.3"
15+
resolved "https://registry.npmjs.org/@types/node/-/node-22.15.3.tgz"
16+
integrity sha512-lX7HFZeHf4QG/J7tBZqrCAXwz9J5RD56Y6MpP0eJkka8p+K0RY/yBTW7CYFJ4VGCclxqOLKmiGP5juQc6MKgcw==
1717
dependencies:
1818
undici-types "~6.21.0"
1919

0 commit comments

Comments
 (0)