4 ms·
For vim, I use a custom command which takes the currently selected code and opens a browser window like this: https://www.gnod.com/search/ai#q=Can%20this%20Pyt
by mg 3y ago
For vim, I use a custom command which takes the currently selected code and opens a browser window like this:
https://www.gnod.com/search/ai#q=Can%20this%20Python%20function%20be%20improved%3F%0A%0Adef%20sum_of_squares(n)%3A%0A%20%20%20%20result%20%3D%200%0A%20%20%20%20for%20i%20in%20range(1%2C%20n%2B1)%3A%0A%20%20%20%20%20%20%20%20result%20%2B%3D%20i**2%0A%20%20%20%20return%20result https://www.gnod.com/search/ai#q=Can%20this%20Python%20funct...
So I can comfortably ask different AI engines to improve it.
The command I use in my vimrc:
command! -range AskAI '<,'>y|call system('chromium gnod.com/search/ai#q='.substitute(iconv(@*, 'latin1', 'utf-8'),'[^A-Za-z0-9_.~-]','\="%".printf("%02X",char2nr(submatch(0)))','g'))
So my workflow when I have a question about some part of my code is to highlight it, hit the : key, that will put :'<,'> on the command line, then I type AskAI<enter>.
All a matter of a second as it already is in my muscle memory.
- nilsherzig 3y agoI think (just my experience) that copilot (the vim edition / plugin) uses more than just the current buffer as a context? It seems to improve when I open related files and starts to know function / type signatures from these buffers as well.
- mg 3y agoThat could be. If so, it would be interesting to know how Copilot does that. For me, just asking LLMs "Can the following function be improved" for a function I just wrote is already pretty useful. The LLM often comes up with a way to make it shorter or more performant.
- nilsherzig 3y agoI just tried the gpt4, without any modifications it's impressively worse than the current chat model
- mg 3y agoWhat did you try?
- nilsherzig 3y agoRunning some queries in a new chatgpt session and via the API. I tried adding the same system prompt on both. I can run one for you, if you want :)
- mg 3y ago"some queries"? Show them, so we can discuss?
- spenczar5 3y agoYes, the official plugin sends context from recently opened other buffers. It determines what context to send by computing a jaccard similarity score locally. It uses a local 14-dimensional logistic regression model as well for some decisions about when to make a completion request, and what to include. There are some reverse-engineering teardowns that show this.
- bmikaili 3y agoFor vim i‘d recommend dedicated plugins: https://github.com/Robitx/gp.nvim https://github.com/Robitx/gp.nvim https://github.com/Robitx/gp.nvim https://github.com/Robitx/gp.nvim
- aiNohY6g 3y agoThere's also https://github.com/David-Kunz/gen.nvim https://github.com/David-Kunz/gen.nvim which works locally with ollama and eg. mistral 7B. Any experience/comparison between them?
- bmikaili 3y agoUh sorry, i was gonna link gen nvim I found gp to have more functions / modes to use it. Gp might be able to support local models using the openai spec, at least i saw an issue in their repo about that.
- deepsquirrelnet 3y agoI don’t have experience with gp.nvim, but I liked David Kunz nvim quite a bit. I ended up forking it into a little pet project so that I could change it a bit more into what I wanted. I love being able to use ollama, but wanted to be able switch to using GPT4 if I needed. I don’t really think automatic replacement is very useful because of how often I need to iterate a response. For me, a better replacement method is to visual highlight in the buffer and hit enter. That way you can iterate with the LLM if needed. Also a bit more fine control with settings like system message, temperature, etc is nice to have. https://github.com/dleemiller/nopilot.nvim https://github.com/dleemiller/nopilot.nvim
- meitham 3y agoThat’s nice! I would like to do something similar but my vim session are all remote over ssh, can we make it work without browser?
- mg 3y agoWithout a browser, I can't think of a solution that is as lean as just putting a line into your vimrc. I guess you have to decide on an LLM that provides an API and write a command line tool that talks to the API. There probably also are open source tools that do this.
- kmarc 3y agojust call a reverse-SSH-tunneled open (macos) or xdg-open (linux) as your netrw browser. I use this daily, works well with gx, :GBrowse, etc