Fork of the neural
nvim plugin just for playing around.
https://github.com/dense-analysis/neural
Neural is a plugin for Neovim that provides blazingly fast AI code generation, editing and completion. It uses OpenAI's GPT-3 API capabilities under the hood to query machine learning models and stream results.
Neural.Demo.mov
Experience lightning-fast code generation and completion with asynchronous streaming from OpenAI's API endpoints that support it.
Become a coding ninja with CTRL+N
to complete code without needing to specify prompt instructions.
Edit any kind of text document. It can be used to generate function docstrings, fix comments spelling/grammar mistakes, generate ideas and more examples from OpenAI.
Code and text results can be unpredictable and inaccurate because they are generated by machine learning models with training data that ends around Jun 2021. Therefore, it may return outdated facts about the world.
All input data (including visually highlighted code and configurable context lines of code) will be sent to OpenAI servers in order to query the machine learning models.
Language generation models based on the transformer architecture have shown strong performance on a variety of natural language tasks such as summarization, language translation and generating human-like text.
Open AI's Codex model has been fine-tuned for code generation tasks and can generate patterns and structures of programming languages using attention mechanisms to focus on specific parts of the input sequence.
Although the resulting output is usually syntactically valid, it must be carefully evaluated for correctness.
- curl - for making HTTP requests
- OpenAI API - for edits/completions querying
- nui.nvim (optional, for UI support)
- significant.nvim (optional, for animated signs)
You will need to obtain an OpenAI API key.
You can clone this repository to a neovim runtime path:
git clone -C ~/.local/share/nvim/site/pack/git-plugins/start/neural https://github.com/dense-analysis/neural.git
Then you will need to add require('neural').setup({})
in your init.vim, passing a minimal configuration
require('neural').setup({
open_ai = {
api_key = '<YOUR OPENAI API SECRET KEY>'
}
}
To install Neural using vim-plug, add the following to your init.vim
:
Plug 'dense-analysis/neural'
Plug 'muniftanjim/nui.nvim'
Plug 'elpiloto/significant.nvim'
Then run :PlugInstall
in Neovim to install Neural.
(NOTE: Not tested yet but should work)
You can use packer.nvim with something like:
use({
'dense-analysis/neural',
config = function()
require('neural').setup({
open_ai = {
api_key = '<YOUR OPENAI API SECRET KEY>'
}
})
end,
requires = {
'MunifTanjim/nui.nvim',
'ElPiloto/significant.nvim'
}
})
You can bring the prompt by pressing CTRL+SPACE
or the reconfigured keybinding in normal, insert, or visual mode. This will bring up a prompt where you can enter your query.
Visually select some code on a buffer to provide context for code editing, and then bring the prompt with CTRL+SPACE
or the reconfigured keybinding. This will edit the code selection guided by the prompt.
For example, to use Neural for code completion, you can type :NeuralCode intelli
in normal mode, or press the configured keybinding in insert or visual mode and enter intelli
at the prompt.
To use Neural for text generation, you can type :NeuralText "The quick brown fox"
in normal mode, or press the configured keybinding in insert or visual mode and enter "The quick brown fox"
at the prompt.
You can run an auto command after a neural result has finished writing to the buffer. This is useful for running linters and fixers, for example:
autocmd User NeuralWritePost ALEFix!
You can use the :NeuralCode
and :NeuralText
commands to specify your query as the arguments.
vnoremap <leader><leader>d :NeuralCode add documentation<CR>
vnoremap <leader><leader>s :NeuralText Fix spelling and grammar and rephrase in a proffesional tone<CR>
You can customize various options, such as the keybindings, highlight colors, icon and more.
You must pass your OpenAI API secret key into the setup in order to query the Open AI API.
require('neural').setup({
open_ai = {
api_key = '<YOUR OPENAI API SECRET KEY>'
}
}
Example of a default configuration:
{
mappings = {
swift = '<C-n>', -- Context completion
prompt = '<C-space>', -- Open prompt
},
-- OpenAI settings
open_ai = {
temperature = 0.1,
presence_penalty = 0.5,
frequency_penalty = 0.5,
max_tokens = 2048,
context_lines = 16, -- Surrounding lines for swift completion
api_key = '<YOUR OPENAI API SECRET KEY>', -- (DO NOT COMMIT)
},
-- Visual settings
ui = {
use_prompt = true, -- Use visual floating Input
use_animated_sign = true, -- Use animated sign mark
show_hl = true,
show_icon = true,
icon = '🗲', -- Prompt/Static sign icon
icon_color = '#ffe030', -- Sign icon color
hl_color = '#4D4839', -- Line highlighting on output
prompt_border_color = '#E5C07B',
},
}
Neural was created by Anexon.
I would like to extend gratitude to the following notable individuals:
- w0rp for providing guidance and golden nuggets from invaluable experience creating & maintaining ALE.
- Munif Tanjim for creating an awesome UI component library nui.nvim.
- Luis Poloto for creating an underrated sign animations plugin significant.nvim.
Neural is released under the MIT license. See LICENSE for more information.