aminroosta / openai.vim

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

openai.vim

A Neovim plugin that exposes OpenAI’s Chat Completion API.

Installation

  1. Add your OPENAI_API_KEY to the environment variables by running the following command in the terminal:
echo 'export OPENAI_API_KEY=your-openai-key' >> ~/.bashrc
  1. (Optional) If you are using an opensource LLM via lmstudio, you can export OPENAI_ENDPOINT by running these commands in the terminal:
echo 'export OPENAI_API_KEY' >> ~/.bashrc
echo 'export OPENAI_ENDPOINT=http://192.168.2.20:1234' >> ~/.bashrc
  1. Using packer.nvim, add the following code to your init.lua file:
require('packer').startup(function()
  use {
    "aminroosta/openai.vim",
    requires = {
      "nvim-lua/plenary.nvim",
      "MunifTanjim/nui.nvim",
    }
  }
end)

Configuration

Add your own commands by modifying require("openai").commands table in your init.lua.
see openai's Chat Completion API documentation for more info.

For example, to add a command that generates a summary of the input text, you can do:

-- TEXT will be replaced with the selected text
require("openai").commands = {
  summary = {
    {
      role = "user",
      content = "Write a summary of the following text:\n\nTEXT"
    }
  },
}

Usage

The plugin exposes a visual mode command :Openai that shows a popup with configured commands.

:'<,'>Openai list

If an argument is given, the popup menu will be skipped.

:'<,'>Openai summary

About


Languages

Language:Lua 80.6%Language:Vim Script 19.4%