gp.nvim icon indicating copy to clipboard operation
gp.nvim copied to clipboard

add agent picker

Open Robitx opened this issue 1 year ago • 2 comments

telescope example thanks to @qaptoR

      local pickers = require 'telescope.pickers'
      local finders = require 'telescope.finders'
      local actions = require 'telescope.actions'
      local action_state = require 'telescope.actions.state'
      local conf = require('telescope.config').values

      local models = function(opts)
        local buf = vim.api.nvim_get_current_buf()
        local file_name = vim.api.nvim_buf_get_name(buf)
        local is_chat = require('gp').not_chat(buf, file_name) == nil

        opts = opts or {}
        pickers
          .new(opts, {
            prompt_title = 'Models',
            finder = finders.new_table {
              results = is_chat and require('gp')._chat_agents or require('gp')._command_agents,
            },
            sorter = conf.generic_sorter(opts),
            attach_mappings = function(prompt_bufnr)
              actions.select_default:replace(function()
                local selection = action_state.get_selected_entry()
                actions.close(prompt_bufnr)
                require('gp').cmd.Agent { args = selection[1] }
              end)
              return true
            end,
          })
          :find()
      end

      vim.keymap.set('n', '<C-g>z', function()
        models(require('telescope.themes').get_dropdown {
          winblend = 10,
          previewer = false,
        })
      end, {
        noremap = true,
        silent = false,
        nowait = true,
        desc = 'GPT prompt Choose Agent',
      })

Originally posted by @qaptoR in https://github.com/Robitx/gp.nvim/discussions/158

Robitx avatar Aug 04 '24 01:08 Robitx

Your snippet was inspiration for me to build telescope extension.

https://github.com/undg/telescope-gp-agent-picker.nvim

image

undg avatar Oct 26 '24 13:10 undg

fzf-lua version

    vim.api.nvim_create_user_command("GpSelectAgent", function()
      local buf = vim.api.nvim_get_current_buf()
      local file_name = vim.api.nvim_buf_get_name(buf)
      local is_chat = require("gp").not_chat(buf, file_name) == nil
      local models = is_chat and require("gp")._chat_agents or require("gp")._command_agents
      local prompt_title = is_chat and 'Chat Models' or 'Completion Models'
      require("fzf-lua").fzf_exec(models, {
        prompt = prompt_title,
        actions = {
          ["default"] = function(selected, _)
            require("gp").cmd.Agent({ args = selected[1] })
          end,
        },
      })
    end, {})

skrobul avatar Jan 31 '25 09:01 skrobul