Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explain Hook does not receive the selected text #141

Open
alivault opened this issue Jun 8, 2024 · 0 comments
Open

Explain Hook does not receive the selected text #141

alivault opened this issue Jun 8, 2024 · 0 comments

Comments

@alivault
Copy link

alivault commented Jun 8, 2024

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:
image
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant