LLM agent with direct Vim access using neovim/pynvim
Project description
VimGPT
Prototype LLM agent with direct Vim access, using neovim/pynvim.
Why?
There are two common options for using LLM agents to edit files:
- Rewrite the entire file: reliable, but very expensive (in time and tokens), and for small changes/big files it is incredibly wasteful and difficult to interpret where the change was made.
- Make a patch: using a patch format such as UDF can make edits much faster and more clear, but is highly error-prone as the current generation of LLMs often make mistakes with line numbers, leading spaces, capitalization, etc.
The Solution: Instead of asking the agent to call a tool with the new contents, give the agent an "Editor" tool which drops into a sub-agent with appropriate context. The simulated editor shows the state of the editor in plaintext, takes individual keystrokes, and reflects updates. This can be conceptualized as individual keystrokes forming tools. And why invent your own when Vim already exists?
Drawbacks
- This tends to be quite fast, but does consume a lot of requests because each command is its own request.
- GPT-3.5 struggles with doing things logically in Vim, so you are limited to GPT-4. (Claude-2.0 untested so far).
Installation
TODO, will be
brew install neovim
pip install vimgpt
Development
This project uses poetry.
# If you don't already have 3.11 installed
pyenv install 3.11:latest
# typical poetry install methods didn't work for me
brew install poetry
# this will create a .venv in the project directory.
# it should automatically check the right version is installed.
poetry install
# view info about your new venv
poetry env list
(Deprecated) Old version using pyenv/virtualenv
pyenv install 3.11:latest
pyenv virtualenv 3.11 k-llm
pyenv activate k-llm
pip install -r requirements.txt
Demo
To run with headless vim:
python demo_headless.py
To attach to a running Neovim instance so you can view what's happening in real-time as the agent does:
NVIM_LISTEN_ADDRESS=/tmp/nvimsocket nvim
# in separate terminal
python demo_attached.py
Publish to PyPI
poetry build
poetry config pypi-token.pypi <YOUR_PYPI_TOKEN>
Roadmap
- pyargs
- in-memory vs file system options
- test on multi-page files
- Cool demo
- CI
- deploy on PyPI
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.