/neural-fork

Primary LanguageLuaMIT LicenseMIT

It's a fork

Fork of the neural nvim plugin just for playing around.

https://github.com/dense-analysis/neural

⚡ Neural

Neovim Lua Join the Dense Analysis Discord server

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

Features

⚡ Fast generation

Experience lightning-fast code generation and completion with asynchronous streaming from OpenAI's API endpoints that support it.

🥷 Swift Context

Become a coding ninja with CTRL+N to complete code without needing to specify prompt instructions.

💡 More than code

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.

Disclaimer

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.

🚨 Use generated code in production systems at your own risk!

Although the resulting output is usually syntactically valid, it must be carefully evaluated for correctness.

🔌 Dependencies

🪄 Installation

You will need to obtain an OpenAI API key.

Manual

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>'
    }
}

Vim Plug

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)

Packer.nvim

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'
    }
})

🚀 Usage

Prompt

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.

Selection + Prompt

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.

Commands

Code completion

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.

Text completion

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.

Events

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!

⌨️ Example prompt shortcuts

You can use the :NeuralCode and :NeuralText commands to specify your query as the arguments.

Add documentation

vnoremap <leader><leader>d :NeuralCode add documentation<CR>

Fix spelling/grammar/tone

vnoremap <leader><leader>s :NeuralText Fix spelling and grammar and rephrase in a proffesional tone<CR>

⚙️ Configuration

You can customize various options, such as the keybindings, highlight colors, icon and more.

Minimal Example

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>'
    }
}

Full example

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',
    },
}

📜 Acknowledgements

Neural was created by Anexon.

I would like to extend gratitude to the following notable individuals:

📙 License

Neural is released under the MIT license. See LICENSE for more information.