A Neovim plugin that exposes OpenAI’s Chat Completion API.
- 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
- (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=https://192.168.2.20:1234' >> ~/.bashrc
- 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)
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"
}
},
}
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