cogentapps / chat-with-gpt

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

fix redundancy in chatManager class #39

Closed mptx1024 closed 1 year ago

mptx1024 commented 1 year ago

The getMessageChainTo() method in the MessageTree class currently returns an array that already includes the message itself, so no need to push it again into the messages array.

cogentapps commented 1 year ago

The code is a bit confusing here and should probably be rewritten to make it more clear, but because getMessageChainTo() is passed message.parentID (as opposed to message.id) it returns the list of messages ending with the previous message - the one being replied to - and not the new message.

The MessageTree class stores messages in a tree structure, where each message keeps track of its parent (the message it was a reply to) and replies (may have multiple replies if the user edited or regenerated a message). getMessageChainTo() scans up through the tree to find the series of messages leading to the new message, not including the new message, and not including any messages on other 'branches' of the tree (like older edits). Hope that makes sense.