Comments (15)
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.
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.
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.
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.
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.
from chatgpt-web.
Here clicking the arrows will bring back all messages that stemmed from message 2 version 1
from chatgpt-web.
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.
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.
Awesome, I'll check it in the morning and add some comments.
from chatgpt-web.
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.
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.
@all-contributors please add @Michael-Tanzer for ideas and code
from chatgpt-web.
I've put up a pull request to add @Michael-Tanzer! 🎉
from chatgpt-web.
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.
Fixed in #152
from chatgpt-web.
Related Issues (20)
- Feature Request: Temporary Prompts for Context-Independent Queries
- Why token counts & costs are 40x? HOT 3
- How often do backups save? HOT 1
- Access to GPT4 0125 preview? HOT 1
- Enhancement: Change favicon HOT 4
- Enter button automatically trigger confirmation of the input text. HOT 1
- Is it possible to start a new chat directly from a URL? HOT 2
- It stucks while responding HOT 1
- [Feature Request] Auto-type as you dictate (speech to text)
- Error: TypeError: Failed to fetch when attempting to generate images with DallE-3
- my local history has gone suddenly, is there any way to get it back, and can I prevent this from happening again? HOT 1
- BUG caused by multiple people using the local area network HOT 1
- Plans on supporting Claude? HOT 4
- Please add support for https HOT 2
- Why can't save API key? HOT 2
- Add Support for gpt-4-turbo-2024-04-09 HOT 4
- Allow model support of gpt-4-turbo HOT 5
- Errors building mocked_api container HOT 2
- Chat Profile creation and edit HOT 2
- Support Batch API
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chatgpt-web.