-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Implement non-blocking CLI history auto saver #1156
base: main
Are you sure you want to change the base?
Conversation
Implements a thread that auto saves history
Ideally this shouldn't be involving the complexity added by another thread, but I am yet to completely figure out the TUI loop/routine lifecycle; In theory, file writing is primarily an I/O bound operation, hence co-routines can be leveraged to avoid blocking the main thread. However, the terminal interface is not implemented with the asyncio. On the other hand, these same file writes occurring within the same thread may also go unnoticed for the following:
What are others' thoughts on this? |
Good lord I'm excited for this. Great work @teocns. Always wanted arrow up, especially for debugging, I hate typing the same message over and over again. I think it would be fine to not be a thread, and just take a tiny but of time to add the user's message. That should take barely any time. Another thought: we do already save Let me know your thoughts, will just merge if you think those^ changes are worse / only marginally better. I think it would work well either way. |
Absolutely - an optimistic average byte size per prompt floats around 64KB for a 128K tokens context window (UTF-8 chars range between 1-4 bytes).
Good catch! The conversations historical data is buffered in memory when launching OI with My two cents: being an I/O-bound-first appllication, and considered the open source scale of the project, I would prioritize OI's refactoring to implement an asynchronous presentation layer (just like the FastAPI server) - to begin with. That'd solve the core issue now and will prevent many more in the future |
Whatever aligns more with the vision and roadmap 👍 I'd buy into this implementation for being efficient, although it comes with the cost of having a "thread" which sounds heavy. Threads can indeed behave funny especially within poorly orchestrated multi-threaded ecosystems, or be draining resources when iteratively spawned at high rates... which doesn't seem to be our case |
Any ideas on when this will be merged? Regarding threading: All the best! |
Describe the changes you have made:
Implement
history_autosaver
utility function to start a background thread for autosaving the CLI history usingreadline
. Ifreadline
is unavailable, it returns a no-op class object instead. This ensures the application remains functional, with or withoutreadline
.autosaver is constructed before the
terminal_interface
loop starts, and history messages are queued via the handle's.add()
method.terminal_interface.py
is now decoupled fromreadline
pyreadline might be a
readline
alternative for other OS-esExtra
cli_input()
handles both single and multi-line inputs by implementing a new argument multi_line, false by default:Reference any relevant issues (e.g. "Fixes #000"):
N/A
Pre-Submission Checklist (optional but appreciated):
I have included relevant documentation updates (stored in /docs)docs/CONTRIBUTING.md
docs/ROADMAP.md
OS Tests (optional but appreciated):
Tested on WindowsTested on Linux