adds db connectivity and saving, need to process user messages still

This commit is contained in:
Daniel Avila 2023-02-05 23:05:07 -05:00
parent f889f23792
commit 254f9d7e26
3 changed files with 100 additions and 12 deletions

View file

@ -1,10 +1,43 @@
/*
{
role: 'assistant',
id: 'cmpl-6gNfeSy5RUJulgpX1vIlppGdyXjB3',
parentMessageId: 'e84f127b-201b-4a1d-8b6d-899e7edab5b4',
conversationId: '97f657cd-be00-490c-94b9-31dba2462a7c',
text: 'OpenAI is an AI research lab consisting of the for-profit technological company OpenAI LP and its parent company, the non-profit OpenAI Inc. It aims to promote and develop friendly AI in a way that benefits humanity as a whole.'
}
*/
const mongoose = require('mongoose');
const messageSchema = mongoose.Schema({
id: {
type: String,
unique: true,
required: true
},
conversationId: {
type: String,
required: true
},
parentMessageId: {
type: String,
required: true
},
sender: {
type: String,
required: true
},
text: {
type: String,
required: true
},
created: {
type: Date,
default: Date.now
}
});
const Message = mongoose.models.Message || mongoose.model('Message', messageSchema);
module.exports = {
saveMessage: async (message) => {
const { text, id, parentMessageId, conversationId } = message;
await Message.create({
id,
conversationId,
parentMessageId,
text
});
}
}