Skip to content

Commit 272bb34

Browse files
committed
refactor(models): simplify model listing by using model_picker_enabled
Remove version field from models in favor of using just ID for model identification. Simplify model and agent listing with consistent sorting by provider and ID. Add model_picker_enabled flag for Copilot models to filter models that should appear in the model picker.
1 parent af4777e commit 272bb34

File tree

2 files changed

+23
-36
lines changed

2 files changed

+23
-36
lines changed

lua/CopilotChat/client.lua

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -296,13 +296,8 @@ function Client:fetch_models()
296296
if ok then
297297
for _, model in ipairs(provider_models) do
298298
model.provider = provider_name
299-
if not model.version then
300-
model.version = model.id
301-
end
302-
303299
if models[model.id] then
304300
model.id = model.id .. ':' .. provider_name
305-
model.version = model.version .. ':' .. provider_name
306301
end
307302
models[model.id] = model
308303
end
@@ -688,46 +683,41 @@ end
688683
---@return table<string, table>
689684
function Client:list_models()
690685
local models = self:fetch_models()
686+
local result = vim.tbl_keys(models)
691687

692-
-- First deduplicate by version, keeping shortest ID
693-
local version_map = {}
694-
for id, model in pairs(models) do
695-
local version = model.version or model.id
696-
if not version_map[version] or #id < #version_map[version] then
697-
version_map[version] = id
698-
end
699-
end
700-
701-
local result = vim.tbl_values(version_map)
702688
table.sort(result, function(a, b)
703-
local a_model = models[a]
704-
local b_model = models[b]
705-
if a_model.provider ~= b_model.provider then
706-
return a_model.provider < b_model.provider -- sort by version first
689+
a = models[a]
690+
b = models[b]
691+
if a.provider ~= b.provider then
692+
return a.provider < b.provider
707693
end
708-
return a_model.version < b_model.version -- then by provider
694+
return a.id < b.id
709695
end)
710696

711-
local out = {}
712-
for _, id in ipairs(result) do
713-
table.insert(out, vim.tbl_extend('force', models[id], { id = id }))
714-
end
715-
return out
697+
return vim.tbl_map(function(id)
698+
return models[id]
699+
end, result)
716700
end
717701

718702
--- List available agents
719703
---@return table<string, table>
720704
function Client:list_agents()
721705
local agents = self:fetch_agents()
722-
723706
local result = vim.tbl_keys(agents)
724-
table.sort(result)
725707

726-
local out = {}
727-
table.insert(out, { id = 'none', name = 'None', description = 'No agent', provider = 'none' })
728-
for _, id in ipairs(result) do
729-
table.insert(out, vim.tbl_extend('force', agents[id], { id = id }))
730-
end
708+
table.sort(result, function(a, b)
709+
a = agents[a]
710+
b = agents[b]
711+
if a.provider ~= b.provider then
712+
return a.provider < b.provider
713+
end
714+
return a.id < b.id
715+
end)
716+
717+
local out = vim.tbl_map(function(id)
718+
return agents[id]
719+
end, result)
720+
table.insert(out, 1, { id = 'none', name = 'None', description = 'No agent', provider = 'none' })
731721
return out
732722
end
733723

lua/CopilotChat/config/providers.lua

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ local utils = require('CopilotChat.utils')
33
---@class CopilotChat.Provider.model
44
---@field id string
55
---@field name string
6-
---@field version string?
76
---@field tokenizer string?
87
---@field max_input_tokens number?
98
---@field max_output_tokens number?
@@ -177,13 +176,12 @@ M.copilot = {
177176
local models = vim
178177
.iter(response.body.data)
179178
:filter(function(model)
180-
return model['capabilities']['type'] == 'chat'
179+
return model.model_picker_enabled and model.capabilities.type == 'chat'
181180
end)
182181
:map(function(model)
183182
return {
184183
id = model.id,
185184
name = model.name,
186-
version = model.version,
187185
tokenizer = model.capabilities.tokenizer,
188186
max_input_tokens = model.capabilities.limits.max_prompt_tokens,
189187
max_output_tokens = model.capabilities.limits.max_output_tokens,
@@ -328,7 +326,6 @@ M.github_models = {
328326
return {
329327
id = model.name,
330328
name = model.displayName,
331-
version = model.name .. '-' .. model.version,
332329
tokenizer = 'o200k_base',
333330
max_input_tokens = model.modelLimits.textLimits.inputContextWindow,
334331
max_output_tokens = model.modelLimits.textLimits.maxOutputTokens,

0 commit comments

Comments
 (0)