効果のデモ#
ChatGPT との対話#
- コマンドラインモードで
NeoAI
を入力すると、右側の端末に対話ボックスが表示され、ブラウザと同じような体験ができます。速度もブラウザと同じくらい速いです。 Esc
キーをクリックすると、対話ボックスを非表示にすることができます。ただし、NeoAI
を再入力するたびに新しいセッションが開始されることに注意してください。- では、対話ボックスを非表示にした後に新しいセッションを開始せずに対話ボックスを再表示するにはどうすればよいでしょうか?
コードの説明#
- ビューモードで選択したコードをコマンドラインモードで
NeoAIContext
と入力すると、選択したコードが ChatGPT にコピーされ、ChatGPT が提供されたコード情報に基づいてより正確な回答を行うことができます。 - コマンドラインモードで直接
NeoAIContext
を入力すると、バッファ全体がコピーされて送信されます。
ドキュメントの作成#
- コマンドラインモードで
NeoAIInject
と入力すると、ChatGPT が対応するドキュメントを生成し、現在開いているファイルに挿入します。
設定の使用#
プラグインの追加#
Lunarvim ユーザーの場合、次のコードを 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 consise 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
},
OPENAI_API_KEY 環境変数の追加#
- ~/.zshrc を開きます(bash を使用している場合は、~/.bashrc を開きます)
sudo vim ~/.zshrc
- 末尾に次の内容を追加します(自分の OPENAI トークンに置き換えてください)
export OPENAI_API_KEY=sk-kSynjjGgqIdsgVIK7iyz$$$$$$$$$$$$KFYkQwJxM8
- 保存して終了します(コマンドラインモードで
wq
を入力します) - 変更を有効にするために次のコマンドを実行します
source ~/.zshrc