Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 27x 27x 27x 1x 1x 1x 18x 18x 1x 1x 1x 1x 1x 1x 41x 41x 5x 5x 41x 1x 1x 1x | "use strict";
// Conversation class to manage a series of messages forming the communication history
// sent to OpenAI API.
class Conversation {
// Initializes a new Conversation instance.
// This instance will hold a list of messages exchanged in the conversation.
// The limit parameter limits the number of messages stored, removing the oldest
// when the limit is exceeded.
constructor(limit) {
this.messages = [];
this.limit = limit || 20;
}
// Retrieve the list of messages in the conversation.
getMessages() {
return this.messages;
}
// Add a new message to the conversation.
// New messages will be appended to the end of the list.
// This method is used to register both user messages and assistant replies.
// If a limit limit is set and exceeded, the oldest message is removed.
addMessage(message) {
this.messages.push(message);
if (this.messages.length > this.limit) {
this.messages.shift();
}
}
}
export { Conversation as default };
|