Giter Site home page Giter Site logo

llm.nvim's Introduction

(yacine's fork of) llm.nvim

Mostly unmaintained, use the main branch

I will not look at issues or comments

A neovim plugin for no frills LLM-assisted programming.

llm.nvim-showcase.mp4

Yacine: "yes!! this is personal and mostly unmaintained. Use the main!"

Yacine's configuration for this specific fork

{
    'yacinemtb/llm.nvim',
    dependencies = { 'nvim-neotest/nvim-nio' },
    config = function()
      -- Manually configure the services
      local system_prompt =
        'You should replace the code that you are sent, only following the comments. Do not talk at all. Only output valid code. Do not provide any backticks that surround the code. Never ever output backticks like this ```. Any comment that is asking you for something should be removed after you satisfy them. Other comments should left alone. Do not output backticks'
      local helpful_prompt = 'You are a helpful assistant. What I have sent are my notes so far. You are very curt, yet helpful.'
      require('llm').setup {
        timeout_ms = 3000,
        services = {
          groq = {
            url = 'https://api.groq.com/openai/v1/chat/completions',
            model = 'llama3-70b-8192',
            api_key_name = 'GROQ_API_KEY',
            system_prompt = system_prompt,
          },
          groq_help = {
            url = 'https://api.groq.com/openai/v1/chat/completions',
            model = 'llama3-70b-8192',
            api_key_name = 'GROQ_API_KEY',
            system_prompt = helpful_prompt,
          },
          openai = {
            url = 'https://api.openai.com/v1/chat/completions',
            model = 'gpt-4o',
            api_key_name = 'OPENAI_API_KEY',
            system_prompt = system_prompt,
          },
          openai_help = {
            url = 'https://api.openai.com/v1/chat/completions',
            model = 'gpt-4o',
            api_key_name = 'OPENAI_API_KEY',
            system_prompt = helpful_prompt,
          },
          claude = {
            url = 'https://api.anthropic.com/v1/messages',
            model = 'claude-3-5-sonnet-20240620',
            api_key_name = 'ANTHROPIC_API_KEY',
            system_prompt = system_prompt,
          },
          claude_help = {
            url = 'https://api.anthropic.com/v1/messages',
            model = 'claude-3-5-sonnet-20240620',
            api_key_name = 'ANTHROPIC_API_KEY',
            system_prompt = helpful_prompt,
          },
        },
      }

      vim.keymap.set('v', '<leader>k', function()
        require('llm').prompt { replace = true, service = 'groq' }
      end, { desc = 'Prompt with groq (replace = true)' })

      vim.keymap.set('v', '<leader>K', function()
        require('llm').prompt { replace = false, service = 'groq_help' }
      end, { desc = 'Prompt with groq (replace = false)' })

      vim.keymap.set('v', '<leader>L', function()
        require('llm').prompt { replace = false, service = 'openai_help' }
      end, { desc = 'Prompt with openai (replace = false)' })

      vim.keymap.set('v', '<leader>l', function()
        require('llm').prompt { replace = true, service = 'openai' }
      end, { desc = 'Prompt with openai (replace = true)' })

      vim.keymap.set('n', '<leader>I', function()
        require('llm').prompt { replace = false, service = 'anthropic' }
      end, { desc = 'Prompt with anthropic (replace = false)' })

      vim.keymap.set('n', '<leader>i', function()
        require('llm').prompt { replace = true, service = 'anthropic_help' }
      end, { desc = 'Prompt with anthropic (replace = true)' })
    end,
  }

Installation

Before using the plugin, set any of GROQ_API_KEY, OPENAI_API_KEY, ANTHROPIC_API_KEY env vars with your api keys.

lazy.nvim

{
    "yacineMTB/llm.nvim",
    dependencies = { "nvim-neotest/nvim-nio" }
}

Usage

setup()

Configure the plugin. This can be omitted to use the default configuration.

require('llm').setup({
    -- How long to wait for the request to start returning data.
    timeout_ms = 10000,
    services = {
        -- Supported services configured by default
        -- groq = {
        --     url = "https://api.groq.com/openai/v1/chat/completions",
        --     model = "llama3-70b-8192",
        --     api_key_name = "GROQ_API_KEY",
        -- },
        -- openai = {
        --     url = "https://api.openai.com/v1/chat/completions",
        --     model = "gpt-4o",
        --     api_key_name = "OPENAI_API_KEY",
        -- },
        -- anthropic = {
        --     url = "https://api.anthropic.com/v1/messages",
        --     model = "claude-3-5-sonnet-20240620",
        --     api_key_name = "ANTHROPIC_API_KEY",
        -- },

        -- Extra OpenAI-compatible services to add (optional)
        other_provider = {
            url = "https://example.com/other-provider/v1/chat/completions",
            model = "llama3",
            api_key_name = "OTHER_PROVIDER_API_KEY",
        }
    }
})

prompt()

Triggers the LLM assistant. You can pass an optional replace flag to replace the current selection with the LLM's response. The prompt is either the visually selected text or the file content up to the cursor if no selection is made.

create_llm_md()

Creates a new llm.md file in the current working directory, where you can write questions or prompts for the LLM.

Example Bindings

vim.keymap.set("n", "<leader>m", function() require("llm").create_llm_md() end)

-- keybinds for prompting with groq
vim.keymap.set("n", "<leader>,", function() require("llm").prompt({ replace = false, service = "groq" }) end)
vim.keymap.set("v", "<leader>,", function() require("llm").prompt({ replace = false, service = "groq" }) end)
vim.keymap.set("v", "<leader>.", function() require("llm").prompt({ replace = true, service = "groq" }) end)

-- keybinds for prompting with openai
vim.keymap.set("n", "<leader>g,", function() require("llm").prompt({ replace = false, service = "openai" }) end)
vim.keymap.set("v", "<leader>g,", function() require("llm").prompt({ replace = false, service = "openai" }) end)
vim.keymap.set("v", "<leader>g.", function() require("llm").prompt({ replace = true, service = "openai" }) end)

Roadmap

Credits

  • Special thanks to yacine and his ask.md vscode plugin for inspiration!

llm.nvim's People

Contributors

melbaldove avatar yacinemtb avatar dimfeld avatar jakobdylanc avatar

Stargazers

Lulzx avatar Chiso avatar  avatar johannes avatar uzair ghori avatar  avatar Sixten Klementsson avatar Pindjouf avatar Lukas Jordan avatar ~ jesse ~ 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.