Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lua/codecompanion/strategies/chat/keymaps/change_adapter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ function M.get_models_list(adapter)
local models_list = vim
.iter(models)
:map(function(key, value)
if type(key) == "string" and value == nil then
-- `models` is already a list
return key
end
if type(value) == "table" and not value.id then
value.id = key
end
Expand Down
33 changes: 33 additions & 0 deletions tests/strategies/chat/test_keymaps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,39 @@ T["Keymaps"]["change_adapter"]["get_models_list returns correct list with object
h.expect_truthy(result.has_formatted_name)
end

T["Keymaps"]["change_adapter"]["get_models_list returns correct list with string models"] = function()
local result = child.lua([[
h.setup_plugin()
config.adapters.http.opts.show_model_choices = true

local mock_adapter = {
schema = {
model = {
default = "gpt-4",
choices = {
"mistral-large-latest",
"pixtral-large-latest",
"gpt-4",
"gpt-3.5-turbo",
}
}
}
}

local list = change_adapter.get_models_list(mock_adapter)
if not list then return nil end

local names = {}
for _, model in ipairs(list) do
table.insert(names, model)
end
return { first_id = names[1], count = #names }
]])

h.eq(result.first_id, "gpt-4")
h.eq(result.count, 4)
end

T["Keymaps"]["change_adapter"]["get_commands_list returns correct list"] = function()
local list = child.lua([[
h.setup_plugin()
Expand Down