Giter Club home page Giter Club logo

Comments (15)

Michael-Tanzer avatar Michael-Tanzer commented on August 19, 2024 1

I don't think discarding is a good idea. One way this could be dealt with is by adding a new field to every message (e.g. versions[]). When a message is edited, all the messages before the one that was edited could add to their versions[] the current new version (= old version + 1), while all the ones that came after would have their version unchanged. The user can now choose what "version" of the chat to look at and only the messages with right version would be shown (simple filter)

from chatgpt-web.

Niek avatar Niek commented on August 19, 2024

Good idea, I started to work on this a bit in commit cd2b9b9. To get it fully working, all messages after the edited one have to be discarded.

from chatgpt-web.

Niek avatar Niek commented on August 19, 2024

But that would be confusing, editing a message other than the last one will affect the context of the messages. That's why ChatGPT removes all later messages if a message is edited.
The way I see it there are 2 options:

  • Discard later messages (like ChatGPT does)
  • Only allow editing the last message (actually this makes more sense to me)

What do you think?

from chatgpt-web.

Michael-Tanzer avatar Michael-Tanzer commented on August 19, 2024

Alternatively you could have a tree-like structure in the messages, something like this:

export const addMessage = (chatId: number, message: Message) => {
  const chats = get(chatsStorage);
  const chat = chats.find((chat) => chat.id === chatId);

  // Check if the message has a parentId, indicating that it's an edited message
  if (message.parentId !== undefined) {
    // Find the parent message
    const parentMessage = findMessageById(chat.messages, message.parentId);

    // Create a new message with the same text and user as the original message,
    // but with a new id and a parentId of the original message's parentId
    const newMessage: Message = {
      id: generateNewMessageId(),
      role: message.role,
      content: message.content,
      usage: message.usage,
      parentId: parentMessage?.id,
      children: [],
    };

    // Add the new message as a child of the original message
    if (parentMessage) {
      parentMessage.children = [...parentMessage.children, newMessage];
    } else {
      chat.messages.push(newMessage);
    }
  } else {
    // If the message doesn't have a parentId, it's a new message
    chat.messages.push({
      ...message,
      id: generateNewMessageId(),
      children: [],
    });
  }

  chatsStorage.set(chats);
};

function findMessageById(messages: Message[], id: number): Message | undefined {
  for (const m of messages) {
    if (m.id === id) {
      return m;
    }
    const childMessage = findMessageById(m.children || [], id);
    if (childMessage) {
      return childMessage;
    }
  }
  return undefined;
}

Where

  export type Message = {
    id: number;
    role: "user" | "assistant" | "system";
    content: string;
    usage?: Usage;
    parentId?: number;
    children?: Message[];
  };

In this case the editing would simply mean adding a new message with a different parent id. Versions could still be used to show the latest version when displaying a chat

from chatgpt-web.

Michael-Tanzer avatar Michael-Tanzer commented on August 19, 2024

But that would be confusing, editing a message other than the last one will affect the context of the messages. That's why ChatGPT removes all later messages if a message is edited. The way I see it there are 2 options:

* Discard later messages (like ChatGPT does)

* Only allow editing the last message (actually this makes more sense to me)

What do you think?

I also wanted to point out that ChatGPT does not discard old messages, you can still see them using the small arrows on the left of the message you edited (see below). This is very similar to my idea.

Screenshot_10
Screenshot_11
Screenshot_12

from chatgpt-web.

Michael-Tanzer avatar Michael-Tanzer commented on August 19, 2024

Here clicking the arrows will bring back all messages that stemmed from message 2 version 1

from chatgpt-web.

Niek avatar Niek commented on August 19, 2024

Ah, I didn't even notice that before, good point. In that case a tree-like structure would indeed be best, although it's not very trivial to iterate through it.

from chatgpt-web.

Michael-Tanzer avatar Michael-Tanzer commented on August 19, 2024

I made a non-functional proof of concept here: #4, unfortunately I have no idea how Svelte works and the pull request is not currently working. Might be a good starting point though.

from chatgpt-web.

Niek avatar Niek commented on August 19, 2024

Awesome, I'll check it in the morning and add some comments.

from chatgpt-web.

Michael-Tanzer avatar Michael-Tanzer commented on August 19, 2024

Fixed the issue in #4 where the new messages were not being shown. The new commit should be backward compatible with the previous implementation, but I haven't tried the message edit functionality

from chatgpt-web.

Niek avatar Niek commented on August 19, 2024

Good one! I think it can be simplified a bit by having only a parentId property - that should be enough to build the whole tree (chats sharing the same parentId are edited versions).

from chatgpt-web.

Niek avatar Niek commented on August 19, 2024

@all-contributors please add @Michael-Tanzer for ideas and code

from chatgpt-web.

allcontributors avatar allcontributors commented on August 19, 2024

@Niek

I've put up a pull request to add @Michael-Tanzer! 🎉

from chatgpt-web.

Michael-Tanzer avatar Michael-Tanzer commented on August 19, 2024

Good one! I think it can be simplified a bit by having only a parentId property - that should be enough to build the whole tree (chats sharing the same parentId are edited versions).

It's definitely possible, it makes iterating over the chat a bit harder though

from chatgpt-web.

Niek avatar Niek commented on August 19, 2024

Fixed in #152

from chatgpt-web.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.