Giter Club home page Giter Club logo

gen.nvim's Introduction

gen.nvim

Generate text using LLMs with customizable prompts

gen_nvim

Video

Local LLMs in Neovim: gen.nvim

Requires

Install

Install with your favorite plugin manager, e.g. lazy.nvim

Example with Lazy

-- Minimal configuration
{ "David-Kunz/gen.nvim" },
-- Custom Parameters (with defaults)
{
    "David-Kunz/gen.nvim",
    opts = {
        model = "mistral", -- The default model to use.
        host = "localhost", -- The host running the Ollama service.
        port = "11434", -- The port on which the Ollama service is listening.
        display_mode = "float", -- The display mode. Can be "float" or "split".
        show_prompt = false, -- Shows the Prompt submitted to Ollama.
        show_model = false, -- Displays which model you are using at the beginning of your chat session.
        no_auto_close = false, -- Never closes the window automatically.
        init = function(options) pcall(io.popen, "ollama serve > /dev/null 2>&1 &") end,
        -- Function to initialize Ollama
        command = function(options)
            return "curl --silent --no-buffer -X POST http://" .. options.host .. ":" .. options.port .. "/api/chat -d $body"
        end,
        -- The command for the Ollama service. You can use placeholders $prompt, $model and $body (shellescaped).
        -- This can also be a command string.
        -- The executed command must return a JSON object with { response, context }
        -- (context property is optional).
        -- list_models = '<omitted lua function>', -- Retrieves a list of model names
        debug = false -- Prints errors and the command which is run.
    }
},

Here are all available models.

Alternatively, you can call the setup function:

require('gen').setup({
  -- same as above
})

Usage

Use command Gen to generate text based on predefined and customizable prompts.

Example key maps:

vim.keymap.set({ 'n', 'v' }, '<leader>]', ':Gen<CR>')

You can also directly invoke it with one of the predefined prompts or your custom prompts:

vim.keymap.set('v', '<leader>]', ':Gen Enhance_Grammar_Spelling<CR>')

Once a conversation is started, the whole context is sent to the LLM. That allows you to ask follow-up questions with

:Gen Chat

and once the window is closed, you start with a fresh conversation.

You can select a model from a list of all installed models with

require('gen').select_model()

Custom Prompts

All prompts are defined in require('gen').prompts, you can enhance or modify them.

Example:

require('gen').prompts['Elaborate_Text'] = {
  prompt = "Elaborate the following text:\n$text",
  replace = true
}
require('gen').prompts['Fix_Code'] = {
  prompt = "Fix the following code. Only ouput the result in format ```$filetype\n...\n```:\n```$filetype\n$text\n```",
  replace = true,
  extract = "```$filetype\n(.-)```"
}

You can use the following properties per prompt:

  • prompt: (string | function) Prompt either as a string or a function which should return a string. The result can use the following placeholders:
    • $text: Visually selected text
    • $filetype: File type of the buffer (e.g. javascript)
    • $input: Additional user input
    • $register: Value of the unnamed register (yanked text)
  • replace: true if the selected text shall be replaced with the generated output
  • extract: Regular expression used to extract the generated result
  • model: The model to use, e.g. zephyr, default: mistral

Tip

User selections can be delegated to Telescope with telescope-ui-select.

gen.nvim's People

Contributors

david-kunz avatar joseconseco avatar abayomi185 avatar leafo avatar alaaibrahim avatar weygoldt avatar smjonas avatar bartman avatar amzd avatar danieleliasib avatar jmdaly avatar wishuuu avatar kamnxt avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.