nodebb-plugin-openai 1.1.0 → 1.2.0

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.
package/library.js CHANGED
@@ -26,6 +26,7 @@ const defaults = {
26
26
  model: 'gpt-3.5-turbo',
27
27
  minimumReputation: 0,
28
28
  allowedGroups: '[]',
29
+ systemPrompt: 'You are a helpful assistant',
29
30
  };
30
31
 
31
32
 
@@ -227,15 +228,25 @@ async function getMessageIds(roomId, uid, start, stop) {
227
228
  );
228
229
  }
229
230
 
230
- async function chatComplete(message) {
231
+ async function chatComplete(messages) {
231
232
  if (!openai) {
232
233
  throw new Error('API not created!');
233
234
  }
234
- const isConversation = Array.isArray(message);
235
- const { model } = await meta.settings.get('openai');
235
+ const isConversation = Array.isArray(messages);
236
+ const { model, systemPrompt } = await getSettings();
237
+ const conversation = [];
238
+ if (systemPrompt) {
239
+ conversation.push({ role: 'system', content: systemPrompt });
240
+ }
241
+ if (isConversation) {
242
+ conversation.push(...messages);
243
+ } else {
244
+ conversation.push({ role: 'user', content: messages });
245
+ }
246
+
236
247
  const chatCompletion = await openai.chat.completions.create({
237
248
  model: model || 'gpt-3.5-turbo',
238
- messages: isConversation ? message : [{ role: 'user', content: message }],
249
+ messages: conversation,
239
250
  });
240
251
 
241
252
  return chatCompletion.choices[0]?.message?.content;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-openai",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "A NodeBB OpenAI plugin",
5
5
  "main": "library.js",
6
6
  "repository": {
@@ -40,7 +40,12 @@
40
40
  <option value="gpt-4">gpt-4</option>
41
41
  </select>
42
42
  </div>
43
+ <div class="">
44
+ <label class="form-label" for="systemPrompt">System Prompt</label>
45
+ <textarea class="form-control" id="systemPrompt" name="systemPrompt" title="System prompt" placeholder="You are a helpful assistant"></textarea>
46
+ </div>
43
47
  </div>
48
+
44
49
  <div class="">
45
50
  <h5 class="fw-bold tracking-tight settings-header">Restrictions</h5>
46
51