gp.nvim
gp.nvim copied to clipboard
Clarify how to enable ChatGPT4 as an agent
In order to chat with ChatGPT4 inside Neovim, I had to add that agent but also disable ChatGPT3.5. Is that how it's supposed to work? If so, that wasn't totally clear to me at first, for what it's worth, though maybe there was something in the docs I missed.
By the way, this plugin interacts delightfully with Github Copilot, which helps write good follow-up questions.
In case it's valuable, here's an excerpt from my init.lua. I'm using lazy to manage plugins.
use {
"robitx/gp.nvim",
config = function()
require("gp").setup({
agents = {
-- Disable ChatGPT 3.5
{
name = "ChatGPT3-5",
},
{
name = "ChatGPT4",
chat = true,
command = true,
-- string with model name or table with model name and parameters
model = { model = "gpt-4-1106-preview", temperature = 1.1, top_p = 1 },
-- system prompt (use this to specify the persona/role of the AI)
system_prompt = "You are a general AI assistant.\n\n"
.. "The user provided the additional info about how they would like you to respond:\n\n"
.. "- If you're unsure don't guess and say you don't know instead.\n"
.. "- Ask question if you need clarification to provide better answer.\n"
.. "- Think deeply and carefully from first principles step by step.\n"
.. "- Zoom out first to see the big picture and then zoom in to details.\n"
.. "- Use Socratic method to improve your thinking and coding skills.\n"
.. "- Don't elide any code from your output if the answer requires coding.\n"
.. "- Take a deep breath; You've got this!\n",
}
}
}
)
-- VISUAL mode mappings
-- s, x, v modes are handled the same way by which_key
require("which-key").register({
-- ...
["<C-g>"] = {
c = { ":<C-u>'<,'>GpChatNew<cr>", "Visual Chat New" },
p = { ":<C-u>'<,'>GpChatPaste<cr>", "Visual Chat Paste" },
t = { ":<C-u>'<,'>GpChatToggle<cr>", "Visual Toggle Chat" },
["<C-x>"] = { ":<C-u>'<,'>GpChatNew split<cr>", "Visual Chat New split" },
["<C-v>"] = { ":<C-u>'<,'>GpChatNew vsplit<cr>", "Visual Chat New vsplit" },
["<C-t>"] = { ":<C-u>'<,'>GpChatNew tabnew<cr>", "Visual Chat New tabnew" },
r = { ":<C-u>'<,'>GpRewrite<cr>", "Visual Rewrite" },
a = { ":<C-u>'<,'>GpAppend<cr>", "Visual Append (after)" },
b = { ":<C-u>'<,'>GpPrepend<cr>", "Visual Prepend (before)" },
i = { ":<C-u>'<,'>GpImplement<cr>", "Implement selection" },
g = {
name = "generate into new ..",
p = { ":<C-u>'<,'>GpPopup<cr>", "Visual Popup" },
e = { ":<C-u>'<,'>GpEnew<cr>", "Visual GpEnew" },
n = { ":<C-u>'<,'>GpNew<cr>", "Visual GpNew" },
v = { ":<C-u>'<,'>GpVnew<cr>", "Visual GpVnew" },
t = { ":<C-u>'<,'>GpTabnew<cr>", "Visual GpTabnew" },
},
n = { "<cmd>GpNextAgent<cr>", "Next Agent" },
s = { "<cmd>GpStop<cr>", "GpStop" },
x = { ":<C-u>'<,'>GpContext<cr>", "Visual GpContext" },
w = {
name = "Whisper",
w = { ":<C-u>'<,'>GpWhisper<cr>", "Whisper" },
r = { ":<C-u>'<,'>GpWhisperRewrite<cr>", "Whisper Rewrite" },
a = { ":<C-u>'<,'>GpWhisperAppend<cr>", "Whisper Append (after)" },
b = { ":<C-u>'<,'>GpWhisperPrepend<cr>", "Whisper Prepend (before)" },
p = { ":<C-u>'<,'>GpWhisperPopup<cr>", "Whisper Popup" },
e = { ":<C-u>'<,'>GpWhisperEnew<cr>", "Whisper Enew" },
n = { ":<C-u>'<,'>GpWhisperNew<cr>", "Whisper New" },
v = { ":<C-u>'<,'>GpWhisperVnew<cr>", "Whisper Vnew" },
t = { ":<C-u>'<,'>GpWhisperTabnew<cr>", "Whisper Tabnew" },
},
},
-- ...
}, {
mode = "v", -- VISUAL mode
prefix = "",
buffer = nil,
silent = true,
noremap = true,
nowait = true,
})
-- NORMAL mode mappings
require("which-key").register({
-- ...
["<C-g>"] = {
c = { "<cmd>GpChatNew<cr>", "New Chat" },
t = { "<cmd>GpChatToggle<cr>", "Toggle Chat" },
f = { "<cmd>GpChatFinder<cr>", "Chat Finder" },
["<C-x>"] = { "<cmd>GpChatNew split<cr>", "New Chat split" },
["<C-v>"] = { "<cmd>GpChatNew vsplit<cr>", "New Chat vsplit" },
["<C-t>"] = { "<cmd>GpChatNew tabnew<cr>", "New Chat tabnew" },
r = { "<cmd>GpRewrite<cr>", "Inline Rewrite" },
a = { "<cmd>GpAppend<cr>", "Append (after)" },
b = { "<cmd>GpPrepend<cr>", "Prepend (before)" },
g = {
name = "generate into new ..",
p = { "<cmd>GpPopup<cr>", "Popup" },
e = { "<cmd>GpEnew<cr>", "GpEnew" },
n = { "<cmd>GpNew<cr>", "GpNew" },
v = { "<cmd>GpVnew<cr>", "GpVnew" },
t = { "<cmd>GpTabnew<cr>", "GpTabnew" },
},
n = { "<cmd>GpNextAgent<cr>", "Next Agent" },
s = { "<cmd>GpStop<cr>", "GpStop" },
x = { "<cmd>GpContext<cr>", "Toggle GpContext" },
w = {
name = "Whisper",
w = { "<cmd>GpWhisper<cr>", "Whisper" },
r = { "<cmd>GpWhisperRewrite<cr>", "Whisper Inline Rewrite" },
a = { "<cmd>GpWhisperAppend<cr>", "Whisper Append (after)" },
b = { "<cmd>GpWhisperPrepend<cr>", "Whisper Prepend (before)" },
p = { "<cmd>GpWhisperPopup<cr>", "Whisper Popup" },
e = { "<cmd>GpWhisperEnew<cr>", "Whisper Enew" },
n = { "<cmd>GpWhisperNew<cr>", "Whisper New" },
v = { "<cmd>GpWhisperVnew<cr>", "Whisper Vnew" },
t = { "<cmd>GpWhisperTabnew<cr>", "Whisper Tabnew" },
},
},
-- ...
}, {
mode = "n", -- NORMAL mode
prefix = "",
buffer = nil,
silent = true,
noremap = true,
nowait = true,
})
-- INSERT mode mappings
require("which-key").register({
-- ...
["<C-g>"] = {
c = { "<cmd>GpChatNew<cr>", "New Chat" },
t = { "<cmd>GpChatToggle<cr>", "Toggle Chat" },
f = { "<cmd>GpChatFinder<cr>", "Chat Finder" },
["<C-x>"] = { "<cmd>GpChatNew split<cr>", "New Chat split" },
["<C-v>"] = { "<cmd>GpChatNew vsplit<cr>", "New Chat vsplit" },
["<C-t>"] = { "<cmd>GpChatNew tabnew<cr>", "New Chat tabnew" },
r = { "<cmd>GpRewrite<cr>", "Inline Rewrite" },
a = { "<cmd>GpAppend<cr>", "Append (after)" },
b = { "<cmd>GpPrepend<cr>", "Prepend (before)" },
g = {
name = "generate into new ..",
p = { "<cmd>GpPopup<cr>", "Popup" },
e = { "<cmd>GpEnew<cr>", "GpEnew" },
n = { "<cmd>GpNew<cr>", "GpNew" },
v = { "<cmd>GpVnew<cr>", "GpVnew" },
t = { "<cmd>GpTabnew<cr>", "GpTabnew" },
},
x = { "<cmd>GpContext<cr>", "Toggle GpContext" },
s = { "<cmd>GpStop<cr>", "GpStop" },
n = { "<cmd>GpNextAgent<cr>", "Next Agent" },
w = {
name = "Whisper",
w = { "<cmd>GpWhisper<cr>", "Whisper" },
r = { "<cmd>GpWhisperRewrite<cr>", "Whisper Inline Rewrite" },
a = { "<cmd>GpWhisperAppend<cr>", "Whisper Append (after)" },
b = { "<cmd>GpWhisperPrepend<cr>", "Whisper Prepend (before)" },
p = { "<cmd>GpWhisperPopup<cr>", "Whisper Popup" },
e = { "<cmd>GpWhisperEnew<cr>", "Whisper Enew" },
n = { "<cmd>GpWhisperNew<cr>", "Whisper New" },
v = { "<cmd>GpWhisperVnew<cr>", "Whisper Vnew" },
t = { "<cmd>GpWhisperTabnew<cr>", "Whisper Tabnew" },
},
},
-- ...
}, {
mode = "i", -- INSERT mode
prefix = "",
buffer = nil,
silent = true,
noremap = true,
nowait = true,
})
end,
}
@rafpaf Hey, good question. I guess the documentation still needs more refinement. 🙂 To switch between the agents, you can use :GpNextAgent or :GpAgent XY while the current buffer is a chat file. If the current buffer is something different (like buffers with standard code), these same commands control the 'Command Agents.'
The currently used agents are saved in a file, so the plugin remembers the last choice across Neovim instances.
I tried @rafpaf config and it's not working for me. I still get now 3.5 instead of 4
Gp: Chat agent: ChatGPT3-5 | Command agent: CodeGPT4
{
name = "ChatGPT3-5",
chat = false,
command = false,
},
{
name = "ChatGPT4",
chat = true,
command = true,
-- string with model name or table with model name and parameters
model = { model = "gpt-4-1106-preview", temperature = 1.1, top_p = 1 },
-- system prompt (use this to specify the persona/role of the AI)
system_prompt = "You are a general AI assistant.\n\n"
.. "The user provided the additional info about how they would like you to respond:\n\n"
.. "- If you're unsure don't guess and say you don't know instead.\n"
.. "- Ask question if you need clarification to provide better answer.\n"
.. "- Think deeply and carefully from first principles step by step.\n"
.. "- Zoom out first to see the big picture and then zoom in to details.\n"
.. "- Use Socratic method to improve your thinking and coding skills.\n"
.. "- Don't elide any code from your output if the answer requires coding.\n"
.. "- Take a deep breath; You've got this!\n",
},
@cserb Hey, so the following ain't working?
Or if you really want to disable the 3.5 permanently - putting the suggested section into config:
agents = {
-- Disable ChatGPT 3.5
{
name = "ChatGPT3-5",
chat = false, -- just name would suffice
command = false, -- just name would suffice
},
{
name = "ChatGPT4",
chat = true,
command = true,
-- string with model name or table with model name and parameters
model = { model = "gpt-4-1106-preview", temperature = 1.1, top_p = 1 },
-- system prompt (use this to specify the persona/role of the AI)
system_prompt = "You are a general AI assistant.\n\n"
.. "The user provided the additional info about how they would like you to respond:\n\n"
.. "- If you're unsure don't guess and say you don't know instead.\n"
.. "- Ask question if you need clarification to provide better answer.\n"
.. "- Think deeply and carefully from first principles step by step.\n"
.. "- Zoom out first to see the big picture and then zoom in to details.\n"
.. "- Use Socratic method to improve your thinking and coding skills.\n"
.. "- Don't elide any code from your output if the answer requires coding.\n"
.. "- Take a deep breath; You've got this!\n",
},
},
what is your ouput from :GpInspectPlugin (using new neovim instance after config change)? I see:
...
_chat_agents = { "ChatGPT4" },
...
@Robitx :GpInspectPlugin returns:
_chat_agents = { "ChatGPT3-5", "ChatGPT4" },
_chat_finder_opened = false,
_command_agents = { "CodeGPT3-5", "CodeGPT4" },
~~The chat is working but the version shown is ChatGPT3-5. And I want both to be ChatGPT4~~
Edit: I don't know what made the difference... honestly. But now it works.
@cserb no problem :slightly_smiling_face: I'm glad you've got it working.