@mongoosejs/studio 0.3.5 → 0.3.6

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.
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const Archetype = require('archetype');
4
+ const assert = require('assert');
4
5
  const authorize = require('../../authorize');
5
6
  const callLLM = require('../../integrations/callLLM');
6
7
  const getModelDescriptions = require('../../helpers/getModelDescriptions');
@@ -16,13 +17,17 @@ const CreateChatMessageParams = new Archetype({
16
17
  content: {
17
18
  $type: 'string'
18
19
  },
20
+ currentDateTime: {
21
+ $type: 'string',
22
+ $validate: v => assert.ok(v == null || v.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/))
23
+ },
19
24
  roles: {
20
25
  $type: ['string']
21
26
  }
22
27
  }).compile('CreateChatMessageParams');
23
28
 
24
29
  module.exports = ({ db, studioConnection, options }) => async function createChatMessage(params) {
25
- const { chatThreadId, initiatedById, content, script, roles } = new CreateChatMessageParams(params);
30
+ const { chatThreadId, initiatedById, content, currentDateTime, script, roles } = new CreateChatMessageParams(params);
26
31
  const ChatThread = studioConnection.model('__Studio_ChatThread');
27
32
  const ChatMessage = studioConnection.model('__Studio_ChatMessage');
28
33
 
@@ -75,7 +80,12 @@ module.exports = ({ db, studioConnection, options }) => async function createCha
75
80
  }
76
81
 
77
82
  const modelDescriptions = getModelDescriptions(db);
78
- const system = systemPrompt + '\n\n' + modelDescriptions + (options?.context ? '\n\n' + options.context : '');
83
+ const system = [
84
+ systemPrompt,
85
+ currentDateTime ? `Current date: ${currentDateTime}` : null,
86
+ modelDescriptions,
87
+ options?.context
88
+ ].filter(Boolean).join('\n\n');
79
89
 
80
90
  // Create the chat message and get LLM response in parallel
81
91
  const chatMessages = await Promise.all([
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const Archetype = require('archetype');
4
+ const assert = require('assert');
4
5
  const authorize = require('../../authorize');
5
6
  const callLLM = require('../../integrations/callLLM');
6
7
  const streamLLM = require('../../integrations/streamLLM');
@@ -17,13 +18,17 @@ const CreateChatMessageParams = new Archetype({
17
18
  content: {
18
19
  $type: 'string'
19
20
  },
21
+ currentDateTime: {
22
+ $type: 'string',
23
+ $validate: v => assert.ok(v == null || v.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/))
24
+ },
20
25
  roles: {
21
26
  $type: ['string']
22
27
  }
23
28
  }).compile('CreateChatMessageParams');
24
29
 
25
30
  module.exports = ({ db, studioConnection, options }) => async function* createChatMessage(params) {
26
- const { chatThreadId, initiatedById, content, script, roles } = new CreateChatMessageParams(params);
31
+ const { chatThreadId, initiatedById, content, currentDateTime, script, roles } = new CreateChatMessageParams(params);
27
32
  const ChatThread = studioConnection.model('__Studio_ChatThread');
28
33
  const ChatMessage = studioConnection.model('__Studio_ChatMessage');
29
34
 
@@ -76,7 +81,12 @@ module.exports = ({ db, studioConnection, options }) => async function* createCh
76
81
  }
77
82
 
78
83
  const modelDescriptions = getModelDescriptions(db);
79
- const system = systemPrompt + '\n\n' + modelDescriptions + (options?.context ? '\n\n' + options.context : '');
84
+ const system = [
85
+ systemPrompt,
86
+ currentDateTime ? `Current date: ${currentDateTime}` : null,
87
+ modelDescriptions,
88
+ options?.context
89
+ ].filter(Boolean).join('\n\n');
80
90
 
81
91
  const userChatMessage = await ChatMessage.create({
82
92
  chatThreadId,
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const Archetype = require('archetype');
4
+ const assert = require('assert');
4
5
  const authorize = require('../../authorize');
5
6
  const callLLM = require('../../integrations/callLLM');
6
7
  const getModelDescriptions = require('../../helpers/getModelDescriptions');
@@ -17,13 +18,17 @@ const CreateChatMessageParams = new Archetype({
17
18
  documentData: {
18
19
  $type: 'string'
19
20
  },
21
+ currentDateTime: {
22
+ $type: 'string',
23
+ $validate: v => assert.ok(v == null || v.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/))
24
+ },
20
25
  roles: {
21
26
  $type: ['string']
22
27
  }
23
28
  }).compile('CreateChatMessageParams');
24
29
 
25
30
  module.exports = ({ db, options }) => async function createChatMessage(params) {
26
- const { model, content, documentData, roles } = new CreateChatMessageParams(params);
31
+ const { model, content, documentData, currentDateTime, roles } = new CreateChatMessageParams(params);
27
32
 
28
33
  await authorize('Model.createChatMessage', roles);
29
34
 
@@ -37,7 +42,12 @@ module.exports = ({ db, options }) => async function createChatMessage(params) {
37
42
  modelDescriptions,
38
43
  'Current draft document:\n' + (documentData || '')
39
44
  ].join('\n\n');
40
- const system = systemPrompt + '\n\n' + context + (options?.context ? '\n\n' + options.context : '');
45
+ const system = [
46
+ systemPrompt,
47
+ currentDateTime ? `Current date: ${currentDateTime}` : null,
48
+ context,
49
+ options?.context
50
+ ].filter(Boolean).join('\n\n');
41
51
 
42
52
  const llmMessages = [{ role: 'user', content: [{ type: 'text', text: content }] }];
43
53
  const res = await callLLM(llmMessages, system, options);
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const Archetype = require('archetype');
4
+ const assert = require('assert');
4
5
  const authorize = require('../../authorize');
5
6
  const streamLLM = require('../../integrations/streamLLM');
6
7
  const getModelDescriptions = require('../../helpers/getModelDescriptions');
@@ -17,13 +18,18 @@ const StreamChatMessageParams = new Archetype({
17
18
  documentData: {
18
19
  $type: 'string'
19
20
  },
21
+ currentDateTime: {
22
+ $type: 'string',
23
+ $transform: v => v == null ? null : decodeURIComponent(v),
24
+ $validate: v => assert.ok(v == null || v.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/))
25
+ },
20
26
  roles: {
21
27
  $type: ['string']
22
28
  }
23
29
  }).compile('StreamChatMessageParams');
24
30
 
25
31
  module.exports = ({ db, options }) => async function* streamChatMessage(params) {
26
- const { model, content, documentData, roles } = new StreamChatMessageParams(params);
32
+ const { model, content, documentData, currentDateTime, roles } = new StreamChatMessageParams(params);
27
33
 
28
34
  await authorize('Model.streamChatMessage', roles);
29
35
 
@@ -37,7 +43,12 @@ module.exports = ({ db, options }) => async function* streamChatMessage(params)
37
43
  modelDescriptions,
38
44
  'Current draft document:\n' + (documentData || '')
39
45
  ].join('\n\n');
40
- const system = systemPrompt + '\n\n' + context + (options?.context ? '\n\n' + options.context : '');
46
+ const system = [
47
+ systemPrompt,
48
+ currentDateTime ? `Current date: ${currentDateTime}` : null,
49
+ context,
50
+ options?.context
51
+ ].filter(Boolean).join('\n\n');
41
52
 
42
53
  const llmMessages = [{ role: 'user', content: [{ type: 'text', text: content }] }];
43
54
  const textStream = streamLLM(llmMessages, system, options);