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
367 stars 63 forks source link

Feature Request: Allow modifying system message using custom code #2

Closed parasshah10 closed 1 year ago

parasshah10 commented 1 year ago

Changing the system message of the character would allow changing the personality of the character over time or adding context without putting it in a new user message as that could cause the ai to get confused between actual user message and the contextual message. Examples would be updating summary, inventory, relationships, events or even relevant past conversations using sematic search etc for the character only for that thread in the system message giving the character a "long-term memory".

This could be done using the processMessages function allowing to add to/overwrite the existing system prompt on a per thread basis so that other threads of same character are not affected.

Edit: I just saw the api.chat and api.completion in the custom-code.md. Would this allow to replace the assistant message on it's turn using the one generated using api?

josephrocca commented 1 year ago

Hey @parasshah10, wondering why you closed this? Custom code being able to edit the character's "personality" in a way that persists across threads would be really cool! Hadn't replied yet because I've been thinking about how it should be implemented.

Self-modifying characters seems like a pretty awesome feature - definitely want to make this possible.

There are 3 different things to think about in terms of characters modifying their own data:

  1. modifying the messages in the current thread (current custom code already allows this)
  2. modifying their own character data (name, system message, ...even their own code) - i.e. stuff that applies across different threads
  3. modifying "private" data - i.e. data that isn't shared in the character link, and is specific to your personal database - this is mentioned as the (not yet implemented) storage object in the custom code doc.

1 is done, but I'm probably going to adjust the implementation a bit (in a backwards-compatible way) to make it easy to "chain" multiple "extensions" together in a way where they won't conflict too much with one another

2 I think could be implemented with a simple character object, and you simply edit the properties like character.name="foo" - similar to storage

3 I'm not 100% sure on yet because I'm now thinking that maybe there should be storage.thread and storage.global or something like that - but I guess people writing custom code could handle that distinction themselves? hmm

Thinking out loud here - if you have any thoughts, or examples of use cases that you think should be supported, that'd be useful!

josephrocca commented 1 year ago

Oh I just realise that you might have closed it because of the note "custom code can now create system messages" in latest release notes - this actually refers to system messages within the current thread (since this is allowed in the ChatML format - you can arbitrarily mix user/ai/system messages). Currently there's no way to edit the first, "personality-defining" system message, or any other data that would make changes that transfer to other threads.

Let's keep this issue open until it's possible for custom code to edit character details like the first, personality system message, and other cross-thread data.

josephrocca commented 1 year ago

This is now possible! Characters can now edit their own system message, custom code, temperature, etc.

Please see custom code docs: https://github.com/josephrocca/OpenCharacters/blob/main/docs/custom-code.md