🌿 feat: Fork Messages/Conversations (#2617)

* typedef for ImportBatchBuilder

* feat: first pass, fork conversations

* feat: fork - getMessagesUpToTargetLevel

* fix: additional tests and fix getAllMessagesUpToParent

* chore: arrow function return

* refactor: fork 3 options

* chore: remove unused genbuttons

* chore: remove unused hover buttons code

* feat: fork first pass

* wip: fork remember setting

* style: user icon

* chore: move clear chats to data tab

* WIP: fork UI options

* feat: data-provider fork types/services/vars and use generic MutationOptions

* refactor: use single param for fork option, use enum, fix mongo errors, use Date.now(), add records flag for testing, use endpoint from original convo and messages, pass originalConvo to finishConversation

* feat: add fork mutation hook and consolidate type imports

* refactor: use enum

* feat: first pass, fork mutation

* chore: add enum for target level fork option

* chore: add enum for target level fork option

* show toast when checking remember selection

* feat: splitAtTarget

* feat: split at target option

* feat: navigate to new fork, show toasts, set result query data

* feat: hover info for all fork options

* refactor: add Messages settings tab

* fix(Fork): remember text info

* ci: test for single message and is target edge case

* feat: additional tests for getAllMessagesUpToParent

* ci: additional tests and cycle detection for getMessagesUpToTargetLevel

* feat: circular dependency checks for getAllMessagesUpToParent

* fix: getMessagesUpToTargetLevel circular dep. check

* ci: more tests for getMessagesForConversation

* style: hover text for checkbox fork items

* refactor: add statefulness to conversation import
This commit is contained in:
Danny Avila 2024-05-05 11:48:20 -04:00 committed by GitHub
parent c8baceac76
commit 25fceb78b7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
37 changed files with 1831 additions and 523 deletions

View file

@ -70,10 +70,12 @@ class ImportBatchBuilder {
* Finishes the current conversation and adds it to the batch.
* @param {string} [title='Imported Chat'] - The title of the conversation. Defaults to 'Imported Chat'.
* @param {Date} [createdAt] - The creation date of the conversation.
* @returns {object} The added conversation object.
* @param {TConversation} [originalConvo] - The original conversation.
* @returns {{ conversation: TConversation, messages: TMessage[] }} The resulting conversation and messages.
*/
finishConversation(title, createdAt) {
finishConversation(title, createdAt, originalConvo = {}) {
const convo = {
...originalConvo,
user: this.requestUserId,
conversationId: this.conversationId,
title: title || 'Imported Chat',
@ -81,11 +83,12 @@ class ImportBatchBuilder {
updatedAt: createdAt,
overrideTimestamp: true,
endpoint: this.endpoint,
model: openAISettings.model.default,
model: originalConvo.model ?? openAISettings.model.default,
};
convo._id && delete convo._id;
this.conversations.push(convo);
return convo;
return { conversation: convo, messages: this.messages };
}
/**
@ -114,7 +117,9 @@ class ImportBatchBuilder {
* @param {string} [messageDetails.messageId] - The ID of the current message.
* @param {boolean} messageDetails.isCreatedByUser - Indicates whether the message is created by the user.
* @param {string} [messageDetails.model] - The model used for generating the message.
* @param {string} [messageDetails.endpoint] - The endpoint used for generating the message.
* @param {string} [messageDetails.parentMessageId=this.lastMessageId] - The ID of the parent message.
* @param {Partial<TMessage>} messageDetails.rest - Additional properties that may be included in the message.
* @returns {object} The saved message object.
*/
saveMessage({
@ -124,22 +129,26 @@ class ImportBatchBuilder {
model,
messageId,
parentMessageId = this.lastMessageId,
endpoint,
...rest
}) {
const newMessageId = messageId ?? uuidv4();
const message = {
...rest,
parentMessageId,
messageId: newMessageId,
conversationId: this.conversationId,
isCreatedByUser: isCreatedByUser,
model: model || this.model,
user: this.requestUserId,
endpoint: this.endpoint,
endpoint: endpoint ?? this.endpoint,
unfinished: false,
isEdited: false,
error: false,
sender,
text,
};
message._id && delete message._id;
this.lastMessageId = newMessageId;
this.messages.push(message);
return message;