-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
45 lines (43 loc) · 1.2 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const fs = require('fs');
const path = require('path');
module.exports = {
init() {
if (!(process.env.APOS_OPENAI_KEY || process.env.APOS_AI_HELPER_MOCK)) {
// We do not document the mock because it is for internal testing
throw new Error('APOS_OPENAI_KEY must be set in your environment');
}
},
i18n: {
aposAiHelper: {
browser: true
}
},
bundle: {
directory: 'modules',
modules: getBundleModuleNames()
},
options: {
textModel: 'gpt-4o',
textMaxTokens: 1000,
// Note: dall-e-3 does not support variations
imageModel: 'dall-e-2'
},
methods(self) {
return {
checkPermissions(req) {
// If the user cannot edit at least one content type, they have
// no business talking to the AI
if (!Object.keys(self.apos.modules).some(type => self.apos.permission.can(req, 'edit', type))) {
throw self.apos.error('forbidden');
}
}
};
}
};
function getBundleModuleNames() {
const source = path.join(__dirname, './modules/@apostrophecms');
return fs
.readdirSync(source, { withFileTypes: true })
.filter(dirent => dirent.isDirectory())
.map(dirent => `@apostrophecms/${dirent.name}`);
}