This PR is my attempt to isolate all the backend logic changes to begin supporting versioned messages. All of the messages in a conversation now have:
index attribute and indicates what number message in the sequence
version indicates which message version this is for a given index
versions is a dynamic attribute that lets you know all of the versions for a message, at this given index, assuming this index is a point where the conversation branched (i.e. branched = true)
With those model changes, a bunch of query logic was updated so that it's pretty easy to create messages and not have to think too hard about what the index and version are.
An old conversation looks like this:
0.1
1.1
2.1
3.1
The first number is the message index, the second number after the decimal is the version of that message. In this start case it's the first version of every message. Now, message index 2 is going to be edited creating a new version and the assistant will reply. Now the messages for this conversation look like this:
0.1
1.1
2.1 2.2
3.1 3.2
The messages at index of 2 both have branched = true and if you check the versions attribute for those you'll get [1,2]. Even though there are two versions of message index 3 it was not branched there so versions will be an empty array. In other words, message 2 is where the UI is going to let you do next/previous and not at message 3.
By default, when you do conversation.messages.for_conversation_version(1) you will get the original message sequence back. But when you do ...(2) or the shorthand conversation.messages.latest_version_for_conversation you get the following message sequence back:
0.1
1.1
2.2
3.2
And it supports more complicated branching such as this. In this example, the user went back to message 1 and branched again from there so there are now 3 different versions of this conversation and the message at index 0 is the only message that is shared between all three versions.
This PR is my attempt to isolate all the backend logic changes to begin supporting versioned messages. All of the messages in a conversation now have:
index
attribute and indicates what number message in the sequenceversion
indicates which message version this is for a given indexversions
is a dynamic attribute that lets you know all of the versions for a message, at this given index, assuming this index is a point where the conversation branched (i.e.branched
= true)With those model changes, a bunch of query logic was updated so that it's pretty easy to create messages and not have to think too hard about what the index and version are.
An old conversation looks like this:
The first number is the message index, the second number after the decimal is the version of that message. In this start case it's the first version of every message. Now, message index 2 is going to be edited creating a new version and the assistant will reply. Now the messages for this conversation look like this:
The messages at
index
of 2 both havebranched
= true and if you check theversions
attribute for those you'll get[1,2]
. Even though there are two versions of message index 3 it was not branched there so versions will be an empty array. In other words, message 2 is where the UI is going to let you do next/previous and not at message 3.By default, when you do
conversation.messages.for_conversation_version(1)
you will get the original message sequence back. But when you do...(2)
or the shorthandconversation.messages.latest_version_for_conversation
you get the following message sequence back:And it supports more complicated branching such as this. In this example, the user went back to message 1 and branched again from there so there are now 3 different versions of this conversation and the message at index 0 is the only message that is shared between all three versions.