@mongoosejs/studio 0.0.76 → 0.0.77
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.
|
@@ -13,6 +13,10 @@ const CreateChatMessageParams = new Archetype({
|
|
|
13
13
|
},
|
|
14
14
|
content: {
|
|
15
15
|
$type: String
|
|
16
|
+
},
|
|
17
|
+
authorization: {
|
|
18
|
+
$type: 'string',
|
|
19
|
+
$required: true
|
|
16
20
|
}
|
|
17
21
|
}).compile('CreateChatMessageParams');
|
|
18
22
|
|
|
@@ -50,7 +54,7 @@ Here is a description of the user's models. Assume these are the only models ava
|
|
|
50
54
|
`.trim();
|
|
51
55
|
|
|
52
56
|
module.exports = ({ db }) => async function createChatMessage(params) {
|
|
53
|
-
const { chatThreadId, userId, content, script } = new CreateChatMessageParams(params);
|
|
57
|
+
const { chatThreadId, userId, content, script, authorization } = new CreateChatMessageParams(params);
|
|
54
58
|
const ChatThread = db.model('__Studio_ChatThread');
|
|
55
59
|
const ChatMessage = db.model('__Studio_ChatMessage');
|
|
56
60
|
|
|
@@ -74,8 +78,8 @@ module.exports = ({ db }) => async function createChatMessage(params) {
|
|
|
74
78
|
getChatCompletion([
|
|
75
79
|
{ role: 'system', content: 'Summarize the following chat thread in 6 words or less, as a helpful thread title' },
|
|
76
80
|
...llmMessages
|
|
77
|
-
]).then(res => {
|
|
78
|
-
const title = res.
|
|
81
|
+
], authorization).then(res => {
|
|
82
|
+
const title = res.response;
|
|
79
83
|
chatThread.title = title;
|
|
80
84
|
return chatThread.save();
|
|
81
85
|
}).catch(() => {});
|
|
@@ -95,9 +99,8 @@ module.exports = ({ db }) => async function createChatMessage(params) {
|
|
|
95
99
|
script,
|
|
96
100
|
executionResult: null
|
|
97
101
|
}),
|
|
98
|
-
getChatCompletion(llmMessages).then(res => {
|
|
99
|
-
const content = res.
|
|
100
|
-
console.log('Content', content, res);
|
|
102
|
+
getChatCompletion(llmMessages, authorization).then(res => {
|
|
103
|
+
const content = res.response;
|
|
101
104
|
return ChatMessage.create({
|
|
102
105
|
chatThreadId,
|
|
103
106
|
role: 'assistant',
|
|
@@ -109,20 +112,27 @@ module.exports = ({ db }) => async function createChatMessage(params) {
|
|
|
109
112
|
return { chatMessages };
|
|
110
113
|
};
|
|
111
114
|
|
|
112
|
-
async function getChatCompletion(messages,
|
|
113
|
-
const response = await fetch('https://
|
|
115
|
+
async function getChatCompletion(messages, authorization) {
|
|
116
|
+
const response = await fetch('https://mongoose-js.netlify.app/.netlify/functions/createChatMessage', {
|
|
114
117
|
method: 'POST',
|
|
115
118
|
headers: {
|
|
116
|
-
Authorization:
|
|
119
|
+
Authorization: authorization,
|
|
117
120
|
'Content-Type': 'application/json'
|
|
118
121
|
},
|
|
119
122
|
body: JSON.stringify({
|
|
120
|
-
model: 'gpt-4o',
|
|
121
|
-
max_tokens: 2500,
|
|
122
|
-
...options,
|
|
123
123
|
messages
|
|
124
124
|
})
|
|
125
|
+
}).then(response => {
|
|
126
|
+
if (response.status < 200 || response.status >= 400) {
|
|
127
|
+
return response.json().then(data => {
|
|
128
|
+
throw new Error(`Mongoose Studio chat completion error: ${data.message}`);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
return response;
|
|
125
132
|
});
|
|
126
133
|
|
|
127
|
-
return await response.json()
|
|
128
|
-
|
|
134
|
+
return await response.json().then(res => {
|
|
135
|
+
console.log('Response', res);
|
|
136
|
+
return res;
|
|
137
|
+
});
|
|
138
|
+
}
|
package/express.js
CHANGED