-
Notifications
You must be signed in to change notification settings - Fork 180
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
Use zero-width delimiters for role tracking in gptel-mode #565
Comments
I like this as a solution that would also make it very simple to edit responses, which is quite a powerful method for guiding output. I can forsee situations where an odd number of separators exist in the buffer, which would cause I also feel this violates the central ethos of gptel that prevented karthik from using response indicators in the first place. You would end up with documents containing invisible characters if you copy-and-paste responses. But I do think it addresses the main issues #546 without introducing more unacceptable problems. Backwards compatibility could be maintained by automatically dropping the separators in buffers where the previous method was used. |
I think the zero-width delimiter approach effectively addresses these concerns while maintaining gptel's simplicity:
A simpler alternative would be to:
This simpler approach might be preferable - users get immediate visual feedback about response regions and can easily fix any corruption using All that said and backtracking a bit, @daedsidog suggested in #343 that simply making regions explicitly visible and allow them to be fixed up with
The zero-width delimiter approach I've suggested, while elegant in some ways, introduces:
On balance perhaps the simplest solution would be:
This would maintain gptel's existing M.O. while giving users the tools they need to manage/edit prompt/response regions effectively. The visual feedback through overlays addresses the "what is marked as what" problem, while manual region control handles edge cases without introducing new complexity. The benefit of #565 the zero width delimiter solution is that with careful editing (avoiding region boundaries) you won't break the prompt response sequence within a buffer. But with the existing text properties mechanism you always will break the sequence because of the way text properties are handled in emacs. That is, more often than not, prompt/response regions will need to be "fixed up after editing the buffer", notwithstanding the sticky patch 25efd55 that @karthink recently introduced to mitigate this (I've found myriad ways to break this with yank and other editing commands). [2025-01-17 Fri 11:32] |
A potential way to introduce this without changing the way gptel fundamentally works would be introducing two customizeable variables like |
Title: Use zero-width delimiters for role tracking with overlay-based highlighting in gptel-mode buffers
This is a proposal for a new approach to tracking and visually distinguishing assistant/user roles in gptel buffers that addresses several long-standing issues (#321, #343) while maintaining compatibility with the existing system.
The Problem
Currently gptel uses text properties to track which sections of text are assistant responses. This approach has proven problematic because:
Proposed Solution
Use zero-width Unicode characters as role delimiters with overlay-based highlighting, but only when gptel-mode is active:
Key aspects:
Implementation
The solution uses two phases:
When gptel-mode is enabled:
When gptel-mode is disabled:
Response Highlighting
Use overlays for visual distinction:
Benefits
Reliable editing operations:
Better user experience:
Technical improvements:
Testing
To test this change:
Notes
Caveat
There is an obvious caveat here. Enabling the mode mutates the buffer. The characters I have chosen are highly unlikely to appear in regular text. One solution might be that instead of predefining two characters, allow these characters to be configurable via buffer local variables or customisation, or have them automatically selected from a set of candidate characters which characters do not appear in the buffer when scanned upon entering gptel-mode.
Related issues: #321, #343
The text was updated successfully, but these errors were encountered: