josephrocca / OpenCharacters

Simple little web interface for creating characters and chatting with them. It's basically a single HTML file - no server. Share characters using a link (character data is stored within the URL itself). All chat data is stored in your browser using IndexedDB. Currently supports OpenAI APIs and ~any Hugging Face model.
https://josephrocca.github.io/OpenCharacters
MIT License
364 stars 60 forks source link

/name does not change the name displayed for existing user messages in the chat #56

Closed kickahaota closed 1 year ago

kickahaota commented 1 year ago

The description of the /name command is a bit ambiguous. Is /name intended to only change the user's name for future messages in the chat (as if the user's name had actually changed in the story at that point)? Or is it intended to change the user's name for the entire chat, including the previous messages (as if the user had made a mistake in choosing their name to begin with)? From looking at the code, it seems like it's intended to change the entire chat... and in that case, there's a bug.

Currently, the /name command does change the user's name in the chat data. And it calls renderMessageLoop to refresh the message display. But renderMessageLoop looks for already-rendered messages that match the ones in the chat data, and doesn't re-render them. And the code that does this comparison doesn't look at the actual name of the user; it just uses character IDs. So the previous chat messages are not re-rerendered, and the old name continues to be displayed. New user messages have the proper name displayed; and reloading the browser tab makes the old messages display correctly.

I don't want to back-seat code, but it seems like a good solution might be to add a rerenderAllMessages option to renderMessageLoop, like the existing triggerBotReply. If that option is set, then you could skip the message-matching loop, and just clear $.messageFeed.innerHTML as if nothing had been matched. Then you could set the rerenderAllMessages option in /name and /avatar's call to renderMessageLoop.

Thanks again for all your work on this!

josephrocca commented 1 year ago

Thanks! :pray: Fixed.

josephrocca commented 1 year ago

Hmm. Seems like for some reason the first time /name is used (after page load/refresh), it doesn't work (and it's not a rendering problem - the name isn't actually changing), but online sometimes

josephrocca commented 1 year ago

Okay, I think I fixed it - please let me know if you run into any problems