"Dead Simple OpenAI Plugin for Neovim"
A neovim plugin for inserting/replacing text generated from OpenAI APIs.
Not feature-rich, just for testing and studying by myself.
Command | Action |
---|---|
:OpenaiCompleteChat | Generate text by the given text as a prompt of chat completion (ChatGPT) |
:OpenaiEditCode | Generate or edit code by the given instruction and/or input code with Codex (DEPRECATED) |
:OpenaiEditText | Edit given text with/without given instruction |
:OpenaiModels | List available model ids with models API |
:OpenaiModerate | Classify given text if it violates OpenAI's Content Policy |
The response of API will be inserted in the current cursor position, or displayed in the screen with vim.notify()
.
:OpenaiCompleteChat What is the answer to life, the universe, and everything?
:OpenaiEditCode Generate fibonacci function in ruby
:OpenaiEditText watz ur name?
:OpenaiModels
:OpenaiModerate I want to kill them all.
Grab a visual block and run commands, then the response will replace selected block, or just be displayed with vim.notify()
.
:'<,'>OpenaiCompleteChat
:'<,'>OpenaiEditCode Make this ruby code recursive
:'<,'>OpenaiEditText
:'<,'>OpenaiEditText Fix the grammar and spelling mistakes. Do not answer to it.
:'<,'>OpenaiModerate
It also can be run with lua:
:lua =require'openai'.complete_chat({prompt=[[What is the answer to life, the universe, and everything?]]})
:lua =require'openai'.edit_code({input=[[def fib(n)\n\treturn fib(n - 1) + fib(n - 2) if n > 1\n\tn\nend]], instruction=[[make it non-recursive]]})
:lua =require'openai'.edit_text({input=[[Every stars are shining.]], instruction=[[Fix the grammar mistakes.]]})
:lua =require'openai'.list_models()
:lua =require'openai'.moderate({input=[[I want to kill them all.]]})
{
'meinside/openai.nvim',
dependencies = { { 'nvim-lua/plenary.nvim' } },
config = function()
require'openai'.setup {
-- NOTE: these are default values:
--credentialsFilepath = '~/.config/openai-nvim.json',
--models = {
-- completeChat = 'gpt-3.5-turbo',
-- editCode = 'code-davinci-edit-001',
-- editText = 'text-davinci-edit-001',
-- moderation = 'text-moderation-latest',
--},
--timeout = 60 * 1000,
}
end,
},
Create openai-nvim.json
file in ~/.config/
:
{
"api_key": "sk-abcdefgHIJKLMNOP0123456789",
"org_id": "org-0987654321qrstuvwXYZ"
}
- Handle API timeouts more generously.
(waiting for PR) - Implement/add all API functions
- Models: can be used with a free account
- Completions
- Chat
- Edits
- Images
- Embeddings
- Audio
- Files
- Fine-tunes
- Moderations: can be used with a free account
MIT