chat-with-gpt icon indicating copy to clipboard operation
chat-with-gpt copied to clipboard

What does parentId do in the code?

Open MirzaHasnat opened this issue 1 year ago • 1 comments

After reviewing and debugging the code, I'm unable to understand the purpose of parentId, since I want to add some message manually os I'm unable to use context in the class(I created for manual adding message),

for adding message manually to the chat I'm using sendMessage() method from chatManager class.

can someone explain why parentId is used for

MirzaHasnat avatar Aug 01 '23 14:08 MirzaHasnat

Good question! Each message in a chat is considered a 'reply' to the one above it. The parent ID is a reference to that earlier message.

If you're wondering why this is needed:

A message can have multiple replies (multiple messages with the same parent ID) when the Regenerate or Edit features are used. In both cases, a new message object is created with the same parent ID as the original. You can think of it like a tree structure. Whenever Regenerate or Edit is used, the tree of messages branches off in new directions.

Tracking the parent IDs makes it possible to list out a single path down through the branches of that tree, for display in the UI and also passing as context to the AI.

cogentapps avatar Aug 02 '23 23:08 cogentapps