Effect Display#
Chatting with ChatGPT#
- By entering
NeoAI
in command line mode, you can bring up the dialog box on the right side of the terminal, which operates just like the browser and is as fast as using the browser. - Pressing the
Esc
key will hide the dialog box. It is important to note that re-enteringNeoAI
each time is equivalent to starting a new session. - So how can you bring up the dialog box again without starting a new session after hiding it?
Explain Code#
- By selecting the code to be passed in view mode and then entering
NeoAIContext
in command line mode, it is equivalent to copying and sending the selected code to ChatGPT, allowing ChatGPT to provide more accurate answers based on the code information you provided. - If you directly enter
NeoAIContext
in command line mode, it is equivalent to copying and sending the entire buffer.
Write Document#
- Entering
NeoAIInject Document Topic to Write
in command line mode will prompt ChatGPT to generate the corresponding document and insert it into the currently opened file.
Configuration Usage#
Add Plugin#
For Lunarvim users, simply add the following code to lvim.plugins:
{
"Bryley/neoai.nvim",
dependencies = {
"MunifTanjim/nui.nvim",
},
cmd = {
"NeoAI",
"NeoAIOpen",
"NeoAIClose",
"NeoAIToggle",
"NeoAIContext",
"NeoAIContextOpen",
"NeoAIContextClose",
"NeoAIInject",
"NeoAIInjectCode",
"NeoAIInjectContext",
"NeoAIInjectContextCode",
},
keys = {
{ "<leader>as", desc = "summarize text" },
{ "<leader>ag", desc = "generate git message" },
},
config = function()
require('neoai').setup {
-- Below are the default options, feel free to override what you would like changed
ui = {
output_popup_text = "NeoAI",
input_popup_text = "Prompt",
width = 30, -- As percentage eg. 30%
output_popup_height = 80, -- As percentage eg. 80%
submit = "<Enter>", -- Key binding to submit the prompt
},
models = {
{
name = "openai",
model = "gpt-3.5-turbo",
params = nil,
},
},
register_output = {
["g"] = function(output)
return output
end,
["c"] = require("neoai.utils").extract_code_snippets,
},
inject = {
cutoff_width = 75,
},
prompts = {
context_prompt = function(context)
return "Hey, I'd like to provide some context for future "
.. "messages. Here is the code/text that I want to refer "
.. "to in our upcoming conversations:\n\n"
.. context
end,
},
mappings = {
["select_up"] = "<C-k>",
["select_down"] = "<C-j>",
},
open_api_key_env = "OPENAI_API_KEY",
shortcuts = {
{
name = "textify",
key = "<leader>as",
desc = "fix text with AI",
use_context = true,
prompt = [[
Please rewrite the text to make it more readable, clear,
concise, and fix any grammatical, punctuation, or spelling
errors
]],
modes = { "v" },
strip_function = nil,
},
{
name = "gitcommit",
key = "<leader>ag",
desc = "generate git commit message",
use_context = false,
prompt = function()
return [[
Using the following git diff generate a concise and
clear git commit message, with a short title summary
that is 75 characters or less:
]] .. vim.fn.system("git diff --cached")
end,
modes = { "n" },
strip_function = nil,
},
},
}
end
},
Add OPENAI_API_KEY Environment Variable#
- Open ~/.zshrc (if you are using bash, open ~/.bashrc)
sudo vim ~/.zshrc
- Add the following content at the end (make sure to replace it with your own OPENAI token)
export OPENAI_API_KEY=sk-kSynjjGgqIdsgVIK7iyz$$$$$$$$$$$$KFYkQwJxM8
- Save and exit (enter
wq
in command line mode) - Make the changes effective
source ~/.zshrc