Skip to content

Allow in-place Chat history editing #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ncoghlan opened this issue May 6, 2025 · 4 comments
Open

Allow in-place Chat history editing #86

ncoghlan opened this issue May 6, 2025 · 4 comments
Labels
enhancement New feature or request

Comments

@ncoghlan
Copy link
Collaborator

ncoghlan commented May 6, 2025

lmstudio-js supports in-place Chat history editing via:

  • offering both mutable and immutable chat history and chat message instances via an internal mutability flag (using the MaybeMutable base class)
  • the .replaceText() method on saved messages (there are also .appendFile() and appendText() methods on messages)
  • the .replaceSystemPrompt() method to remove all previously added system prompt messages and insert the given prompt at the start of the chat history
  • the .filterInPlace() method to process all currently saved messages with the given filtering callback
  • the .pop() method
  • supporting direct iteration over and indexed access to the messages saved in the chat history

The Python SDK should offer similar capabilities (although the exact spelling may differ).

@ncoghlan ncoghlan assigned ncoghlan and unassigned ncoghlan May 6, 2025
@ncoghlan ncoghlan added enhancement New feature or request good first issue Good for newcomers and removed good first issue Good for newcomers labels May 12, 2025
@ncoghlan
Copy link
Collaborator Author

I was going to mark this as "Good first issue", since the TypeScript SDK offers a starting point for the Python SDK API design, but there are some open design questions that need to be answered before it would really qualify for that marker.

There's no specific ETA on resolving those questions (folks that genuinely need this capability aren't blocked by the absence of a supported API, they just need to tinker with the ._messages field directly, which they understandably would prefer not to be doing).

@NullMagic2
Copy link

The problem with modifying ._messages is that you need to know how the object is structured internally, and there's no guarantee the implementation will remain constant. If you want to allow _messages to be modified, at the very least the internal structure would have to be well-documented in the API / tutorial.

@yagil
Copy link
Member

yagil commented May 13, 2025

@NullMagic2 what about creating a an empty Chat object, iterating over the old one and appending / modifying as needed?

@NullMagic2
Copy link

@NullMagic2 what about creating a an empty Chat object, iterating over the old one and appending / modifying as needed?

For my own solution, I'm creating my own chat object and then converting to the proper format using Chat.from_history() but that's much slower and less than ideal when compared to simple in-place editing.

The reason I do that as opposed to just editing ._messages is because Chat.from_history() is a public documented API, and if I have my own structure, at least I know it'll behave a particular way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants