nodebb-plugin-openai 1.4.3 → 1.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,7 @@
2
2
  "error.need-x-reputation-to-mention": "You need at least %1 reputation for mentioning chatgpt",
3
3
  "summarize-topic": "Summarize Topic",
4
4
  "topic-summary": "Topic Summary",
5
+ "summary-cooldown-error": "You must wait before summarizing a topic again.",
5
6
 
6
7
  "admin.general": "General",
7
8
  "admin.apikey": "API Key",
@@ -2,6 +2,7 @@
2
2
  "error.need-x-reputation-to-mention": "You need at least %1 reputation for mentioning chatgpt",
3
3
  "summarize-topic": "Summarize Topic",
4
4
  "topic-summary": "Topic Summary",
5
+ "summary-cooldown-error": "You must wait before summarizing a topic again.",
5
6
 
6
7
  "admin.general": "General",
7
8
  "admin.apikey": "API Key",
@@ -2,6 +2,7 @@
2
2
  "error.need-x-reputation-to-mention": "דרושה לך מוניטין של %1 לפחות כדי לאזכר את chatgpt",
3
3
  "summarize-topic": "סכם נושא",
4
4
  "topic-summary": "סיכום הנושא",
5
+ "summary-cooldown-error": "עליך להמתין לפני שתסכם את הנושא שוב.",
5
6
 
6
7
  "admin.general": "כללי",
7
8
  "admin.apikey": "מפתח API",
@@ -1,5 +1,6 @@
1
1
  {
2
2
  "error.need-x-reputation-to-mention": "提及 chatgpt 至少需要 %1 声望值",
3
3
  "summarize-topic": "总结主题",
4
- "topic-summary": "主题摘要"
4
+ "topic-summary": "主题摘要",
5
+ "summary-cooldown-error": "在再次总结主题之前,您必须等待。"
5
6
  }
package/library.js CHANGED
@@ -18,6 +18,11 @@ const groups = require.main.require('./src/groups');
18
18
  const sockets = require.main.require('./src/socket.io');
19
19
  const socketPlugins = require.main.require('./src/socket.io/plugins');
20
20
  const summary = require('./lib/summary');
21
+ const cacheCreate = require('../cache/lru');
22
+ const summaryCache = cacheCreate({
23
+ name: 'openai-summary',
24
+ max: 200,
25
+ });
21
26
 
22
27
  const plugin = module.exports;
23
28
 
@@ -26,7 +31,7 @@ const defaults = {
26
31
  'chatgpt-username': '',
27
32
  enablePrivateMessages: 'off',
28
33
  model: 'gpt-3.5-turbo',
29
- minimumReputation: 0,
34
+ minimumReputation: 2,
30
35
  allowedGroups: '[]',
31
36
  systemPrompt: 'You are a helpful assistant',
32
37
  };
@@ -330,16 +335,22 @@ socketPlugins.openai.summarizeTopic = async function (socket, data) {
330
335
  if (!await privileges.topics.can('topics:read', tid, socket.uid)) {
331
336
  throw new Error('[[error:no-privileges]]');
332
337
  }
333
- const settings = await getSettings();
334
- if (!await canUseOpenAI(socket.uid, settings)) {
335
- return;
336
- }
337
338
 
338
339
  let openaiSummary = await topics.getTopicField(tid, 'openai:summary');
339
340
  if (openaiSummary) {
340
341
  return openaiSummary;
341
342
  }
343
+ const settings = await getSettings();
344
+ if (!await canUseOpenAI(socket.uid, settings)) {
345
+ return;
346
+ }
347
+ const cooldown = summaryCache.get(`uid:${socket.uid}`);
348
+ if (cooldown) {
349
+ throw new Error('[[openai:summary-cooldown-error]]');
350
+ }
351
+
342
352
  openaiSummary = await summary.summarizeTopic(tid, openai, settings);
353
+ summaryCache.set(`uid:${socket.uid}`, 1, 60000);
343
354
  await topics.setTopicField(tid, 'openai:summary', openaiSummary);
344
355
  return openaiSummary;
345
356
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-openai",
3
- "version": "1.4.3",
3
+ "version": "1.4.4",
4
4
  "description": "A NodeBB OpenAI plugin",
5
5
  "main": "library.js",
6
6
  "repository": {