feature: Allow changing Copilot models on the fly
Feature request
Allow changing copilot models without changing config (maybe as a second parameter on AvanteSwitchProvider copilot
also could be interesting to check for available models somehow (CopilotChat has some kind of fetch_models for :CopilotChatModels, which brings a select)
Hello! I've implemented a workaround for this case. You can now switch the Copilot model at runtime using <leader>am.
Here's my current avante.nvim configuration:
return {
{
"yetone/avante.nvim",
event = "VeryLazy",
lazy = false,
version = false, -- Use "*" for latest release, or false for latest code.
opts = {
provider = "copilot",
copilot = {
model = "claude-3.7-sonnet", -- Default model
},
},
build = "make",
dependencies = {
"nvim-treesitter/nvim-treesitter",
"stevearc/dressing.nvim",
"nvim-lua/plenary.nvim",
"MunifTanjim/nui.nvim",
"nvim-tree/nvim-web-devicons",
"zbirenbaum/copilot.lua",
{
"HakonHarnes/img-clip.nvim",
event = "VeryLazy",
opts = {
default = {
embed_image_as_base64 = false,
prompt_for_file_name = false,
drag_and_drop = { insert_mode = true },
use_absolute_path = true,
},
},
},
{
"MeanderingProgrammer/render-markdown.nvim",
opts = {
file_types = { "markdown", "Avante" },
},
ft = { "markdown", "Avante" },
},
},
config = function(_, opts)
local available_models = {
["claude-3.7-sonnet"] = { model = "claude-3.7-sonnet" },
["claude-3.7-sonnet๐
โโ๏ธ๐ ๏ธ"] = { model = "claude-3.7-sonnet", disable_tools = true },
["claude-3.5-sonnet"] = { model = "claude-3.5-sonnet" },
["o3-mini-high"] = { model = "o3-mini", reasoning_effort = "high" },
["o4-mini-high"] = { model = "o4-mini", reasoning_effort = "high" },
["o4-mini-high๐
โโ๏ธ๐ ๏ธ"] = { model = "o4-mini", reasoning_effort = "high", disable_tools = true },
["o3-mini"] = { model = "o3-mini" },
["o4-mini"] = { model = "o4-mini" },
["4o"] = { model = "gpt-4o" },
["4.1"] = { model = "gpt-4.1" },
["4.1๐
โโ๏ธ๐ ๏ธ"] = { model = "gpt-4.1", disable_tools = true },
["4.1-mini"] = { model = "gpt-4.1-mini" },
["gemini-2.5-pro"] = { model = "gemini-2.5-pro" },
["gemini-2.5-pro๐
โโ๏ธ๐ ๏ธ"] = { model = "gemini-2.5-pro", disable_tools = true },
["gemini-2.0-flash"] = { model = "gemini-2.0-flash" },
["o2"] = { model = "o2" },
["o3"] = { model = "o3" },
["o1"] = { model = "o1", reasoning_effort = "high" },
}
local function switch_model()
local model_keys = vim.tbl_keys(available_models)
vim.ui.select(model_keys, { prompt = "Select Avante Model:" }, function(selected)
if selected then
opts.copilot = available_models[selected]
require("avante").setup(opts)
print("Switched Copilot model to: " .. selected)
else
print("Model selection canceled.")
end
end)
end
vim.keymap.set("n", "<leader>am", switch_model, { desc = "Avante: Switch Copilot Model" })
require("avante").setup(opts)
print("Avante.nvim configured. Use <leader>am to switch models at runtime.")
end,
},
}
@Properrr sorry it seems the markdown syntax broke there. still, reading a bit it seems like you're hardcoding all the models currently available there?
Still would be nice to have this as a feature, but I'll take a look at your workaround
you can pull the models like this
PS: maybe this is worth generalizing, there's a similar request for ollama: #1581; separating models and provders makes sense
fixed in https://github.com/yetone/avante.nvim/pull/2106