cogentapps / chat-with-gpt

An open-source ChatGPT app with a voice
https://www.chatwithgpt.ai
MIT License
2.29k stars 485 forks source link

What does parentId do in the code? #175

Open MirzaHasnat opened 11 months ago

MirzaHasnat commented 11 months ago

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

cogentapps commented 11 months ago

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.