Giter Site home page Giter Site logo

dante.nvim's Introduction

✒️ Dante

An unpolished grammar checker powered by OpenAI models and Neovim builtin diff tool. Seriously, it's just a proof of concept.

example usage

💡 Idea

I wanted to experiment with the newly released GPT Assistant API. Vim/Neovim's builtin diff tool is a good way to highlight the differences between the original text and the suggested one.

Edit: I moved from the GPT Assistant API back to the chat completions API because it was easier to implement the API in a non-blocking fashion.

The detailed reasons why I decided to develop dante.nvim are explained in this Reddit post.

✨ Features

  • Prompt selected line into LLM and highlight the differences with the original text.

⚡️ Requirements

  • Neovim >= 0.9
  • curl
  • Access to OpenAI API or compatible API (e.g. LiteLLM)

📦 Installation

  1. Install using a plugin manager
-- using lazy.nvim
{
  "s1m0n38/dante.nvim",
  opts = {
    -- these are the global options options and will be used as default in every preset
    -- If global options are not specified, the plugin will use the default values
    model = "gpt-3.5-turbo",
    temperature = 0,

    presets = {
      default = {
        -- when options are not specified, the global config will be used
      },
      readme = {
        -- these options will override the global config
        model = "gpt-4",
        temperature = 0.3,
        prompt = "You are tasked as an assistant primarily responsible for rectifying errors within English text. Please amend spelling inaccuracies and augment grammar; ensure that the refined text closely adheres to the original version. Given that the text is authored in markdown intended for a README file, please abide by the markdown syntax accordingly. Provide your corrections in the form of the enhanced text only, devoid of commentary. Maintain the integrity of the original text's new lines and the spacing. Do NOT enclose the genereate text into triple ticks.",
      },
      -- Add more presets here...
    },
  },

  -- Not required but it improve upon built-in diff view with char diff
  dependencies = {
    {
      "rickhowe/diffchar.vim",
      keys = {
        { "[z", "<Plug>JumpDiffCharPrevStart", desc = "Previous diff", silent = true },
        { "]z", "<Plug>JumpDiffCharNextStart", desc = "Next diff", silent = true },
        -- { "do", "<Plug>GetDiffCharPair", desc = "Obtain diff", silent = true },
        -- { "dp", "<Plug>PutDiffCharPair", desc = "Put diff", silent = true },
        {
          "do",
          "<Plug>GetDiffCharPair | <Plug>JumpDiffCharNextStart",
          desc = "Obtain diff and Next diff",
          silent = true,
        },
        {
          "dp",
          "<Plug>PutDiffCharPair | <Plug>JumpDiffCharNextStart",
          desc = "Put diff and Next diff",
          silent = true,
        },
      },
    },
  },
}
  1. get an OpenAI API key and add it to your environment as OPENAI_API_KEY.

🚀 Usage

Normal Mode

  • :Dante <preset> sends the current line to LLM. If no preset is specified, the default preset will be used.

Visual Mode

  • :'<,'>Dante <preset> sends the selected lines to LLM. If no preset is specified, the default preset will be used.

Read the Neovim documentation to learn how to navigate between and edit differences.

For obtaining the best results, you should:

  • Carefully write your own prompt for your specific use case.
  • Avoid breaking lines at a fixed column (e.g. 80). Instead, use a new line when you feel it's necessary (just like writing with pen and paper) or a double new line for paragraph separation.
  • Selecting smaller chunks of text focuses on the details, but you may miss the big picture.
  • Use a powerful model like gpt-4, but it's more expensive and slower.
  • For text files with a lot of lines, you may want to increase the "linematch" diffopt to 300 or more. This is a temporary workaround until I find a better solution.

⚠️ Warnings

Be cautious of the text your are feeding into Dante. There is no mechanism to mitigate prompt injection and the resulting text can be unexpected.

example prompt-injection

🙏 Acknowledgments

This plugin was heavily inspired by:

This very README is a copycat of lazy.nvim README.

dante.nvim's People

Contributors

isaksamsten avatar s1m0n38 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

isaksamsten

dante.nvim's Issues

Docs

Write the vim style docs.

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.