Skip to content

Commit 56b67a6

Browse files
committed
add 4.1, update eslint
1 parent 9082bf8 commit 56b67a6

File tree

7 files changed

+3618
-1872
lines changed

7 files changed

+3618
-1872
lines changed

eslint.config.mjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use strict';
2+
3+
import serverConfig from 'eslint-config-nodebb';
4+
import publicConfig from 'eslint-config-nodebb/public';
5+
6+
export default [
7+
...publicConfig,
8+
...serverConfig,
9+
];
10+

lib/summary.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const user = require.main.require('./src/user');
88

99
function formatPosts(posts) {
1010
return posts
11-
.map((post) => `User ${post.username}:\n${post.content}`)
11+
.map(post => `User ${post.username}:\n${post.content}`)
1212
.join('\n---\n');
1313
}
1414

@@ -17,7 +17,6 @@ function chunkPosts(posts, maxTokensPerChunk = 3000) {
1717
let currentChunk = [];
1818
let currentTokens = 0;
1919

20-
// eslint-disable-next-line no-restricted-syntax
2120
for (const post of posts) {
2221
const estimatedTokens = Math.ceil(post.content.length / 4) + 10;
2322
if (currentTokens + estimatedTokens > maxTokensPerChunk) {
@@ -59,7 +58,7 @@ async function summarizeChunk(chunk, openai, settings) {
5958
return response.choices[0].message.content.trim();
6059
}
6160

62-
exports.summarizeTopic = async function(tid, openai, settings) {
61+
exports.summarizeTopic = async function (tid, openai, settings) {
6362
const allPids = await topics.getPids(tid);
6463

6564
const userMap = {};
@@ -68,11 +67,11 @@ exports.summarizeTopic = async function(tid, openai, settings) {
6867

6968
await batch.processArray(allPids, async function (pids) {
7069
let postData = await posts.getPostsFields(pids, ['uid', 'content', 'deleted']);
71-
postData = postData.filter((p) => !p.deleted);
70+
postData = postData.filter(p => !p.deleted);
7271
const missingUids = [];
7372
postData.forEach((p) => {
7473
if (!userMap.hasOwnProperty(p.uid)) {
75-
missingUids.push(p.uid)
74+
missingUids.push(p.uid);
7675
}
7776
});
7877
const userData = await user.getUsersFields(missingUids, ['username']);
@@ -86,7 +85,7 @@ exports.summarizeTopic = async function(tid, openai, settings) {
8685
const chunks = chunkPosts(postData);
8786

8887
chunkSummaries.push(...await Promise.all(chunks.map(async (chunk) => {
89-
return summarizeChunk(chunk, openai, settings)
88+
return summarizeChunk(chunk, openai, settings);
9089
})));
9190
}, {
9291
batch: 500,
@@ -96,7 +95,7 @@ exports.summarizeTopic = async function(tid, openai, settings) {
9695
return chunkSummaries[0];
9796
}
9897
// Final summary from all summaries
99-
const finalInput = chunkSummaries.join("\n\n");
98+
const finalInput = chunkSummaries.join('\n\n');
10099
if (!finalInput) {
101100
return '';
102101
}
@@ -118,6 +117,6 @@ exports.summarizeTopic = async function(tid, openai, settings) {
118117
return finalResponse.choices[0].message.content.trim();
119118
};
120119

121-
exports.clearTopicSummary = async function(tids) {
122-
await db.deleteObjectFields(tids.map((tid) => `topic:${tid}`), ['openai:summary']);
120+
exports.clearTopicSummary = async function (tids) {
121+
await db.deleteObjectFields(tids.map(tid => `topic:${tid}`), ['openai:summary']);
123122
};

library.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,19 @@ const defaults = {
3434

3535
plugin.init = async (params) => {
3636
const { router /* , middleware , controllers */ } = params;
37-
const settings = await meta.settings.get('openai')
37+
const settings = await meta.settings.get('openai');
3838
if (settings && settings.apikey) {
3939
openai = new OpenAI({
4040
apiKey: settings.apikey,
4141
});
42+
plugin.openai = openai;
4243
}
4344

4445
routeHelpers.setupAdminPageRoute(router, '/admin/plugins/openai', controllers.renderAdminPage);
4546
};
4647

4748
async function getSettings() {
48-
const settings = await meta.settings.get('openai')
49+
const settings = await meta.settings.get('openai');
4950
return {...defaults, ...settings };
5051
}
5152

@@ -150,7 +151,7 @@ plugin.actionMessagingSave = async function (hookData) {
150151
let messages = await messaging.getMessagesFields(mids, ['fromuid', 'content', 'system']);
151152
messages = messages.filter(m => m && !m.system);
152153
conversation = messages.map(
153-
(msg) => ({ role: msg.fromuid === chatgptUid ? 'assistant' : 'user', content: msg.content })
154+
msg => ({ role: msg.fromuid === chatgptUid ? 'assistant' : 'user', content: msg.content })
154155
);
155156
}
156157

@@ -180,7 +181,8 @@ async function canUseOpenAI(uid, settings, silent = false) {
180181

181182
async function checkReputation(uid, settings, silent) {
182183
const reputation = await user.getUserField(uid, 'reputation');
183-
const hasEnoughRep = parseInt(settings.minimumReputation, 10) === 0 || parseInt(reputation, 10) >= parseInt(settings.minimumReputation, 10);
184+
const hasEnoughRep = parseInt(settings.minimumReputation, 10) === 0 ||
185+
parseInt(reputation, 10) >= parseInt(settings.minimumReputation, 10);
184186

185187
if (!hasEnoughRep && !silent) {
186188
sockets.server.in(`uid_${uid}`).emit('event:alert', {

0 commit comments

Comments
 (0)