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

add agent picker #187

Open
Robitx opened this issue Aug 4, 2024 · 2 comments
Open

add agent picker #187

Robitx opened this issue Aug 4, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@Robitx
Copy link
Owner

Robitx commented Aug 4, 2024

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 #158

@Robitx Robitx added the enhancement New feature or request label Aug 4, 2024
@undg
Copy link

undg commented Oct 26, 2024

Your snippet was inspiration for me to build telescope extension.

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

image

@skrobul
Copy link

skrobul commented Jan 31, 2025

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, {})

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

No branches or pull requests

3 participants