I have copied the Explain hook exactly as the docs show into my config. But when I select some code and run the explain command, I get a pop up that says it didn't receive any selected text, only the filepath:
Here is my current config:
return {
"robitx/gp.nvim",
config = function()
require("gp").setup({
openai_api_key = os.getenv("OPENAI_API_KEY"),
agents = {
{
name = "GPT-4o",
chat = true,
command = true,
model = { model = "gpt-4o", temperature = 1.1, top_p = 1 },
system_prompt = "You are a helpful assistant. Keep your answers concise. When providing code, put the code in triple backticks for markdown formatting. Use 'typescript' for tsx and ts code blocks, never 'typescriptreact'.",
},
},
hooks = {
-- explains the selected code
Explain = function(gp, params)
local template = "I have the following code from {{filename}}:\n\n"
.. "```{{filetype}}\n{{selection}}\n```\n\n"
.. "Please respond by explaining the code above."
local agent = gp.get_chat_agent()
gp.Prompt(params, gp.Target.popup, nil, agent.model, template, agent.system_prompt)
end,
-- opens new chat with the entire current buffer as a context
BufferChatNew = function(gp, _)
-- call GpChatNew command in range mode on whole buffer
vim.api.nvim_command("%" .. gp.config.cmd_prefix .. "ChatNew")
end,
},
chat_confirm_delete = false,
})
end,
}
Sidenote, the BufferChatNew hook works perfectly. But the Explain hook is not receiving the selected text.
I have copied the Explain hook exactly as the docs show into my config. But when I select some code and run the explain command, I get a pop up that says it didn't receive any selected text, only the filepath:
Here is my current config:
Sidenote, the BufferChatNew hook works perfectly. But the Explain hook is not receiving the selected text.