Skip to content

Commit

Permalink
fix: #48 calling unused adapters
Browse files Browse the repository at this point in the history
  • Loading branch information
olimorris committed Apr 24, 2024
1 parent e8c749a commit 12fd54c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ You only need to the call the `setup` function if you wish to change any of the
```lua
require("codecompanion").setup({
adapters = {
anthropic = require("codecompanion.adapters").use("anthropic"),
ollama = require("codecompanion.adapters").use("ollama"),
openai = require("codecompanion.adapters").use("openai"),
anthropic = "anthropic",
ollama = "ollama",
openai = "openai",
},
strategies = {
chat = "openai",
Expand Down
8 changes: 4 additions & 4 deletions doc/codecompanion.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*codecompanion.txt* For NVIM v0.9.2 Last change: 2024 April 08
*codecompanion.txt* For NVIM v0.9.2 Last change: 2024 April 24

==============================================================================
Table of Contents *codecompanion-table-of-contents*
Expand Down Expand Up @@ -75,9 +75,9 @@ Click to see the default configuration ~
>lua
require("codecompanion").setup({
adapters = {
anthropic = require("codecompanion.adapters").use("anthropic"),
ollama = require("codecompanion.adapters").use("ollama"),
openai = require("codecompanion.adapters").use("openai"),
anthropic = "anthropic",
ollama = "ollama",
openai = "openai",
},
strategies = {
chat = "openai",
Expand Down
6 changes: 3 additions & 3 deletions lua/codecompanion/adapters/ollama.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
local log = require("codecompanion.utils.log")

local function get_ollama_choices()
local handle = io.popen 'ollama list'
local handle = io.popen("ollama list")
local result = {}

if handle then
for line in handle:lines() do
local first_word = line:match '%S+'
if first_word ~= nil and first_word ~= 'NAME' then
local first_word = line:match("%S+")
if first_word ~= nil and first_word ~= "NAME" then
table.insert(result, first_word)
end
end
Expand Down
18 changes: 11 additions & 7 deletions lua/codecompanion/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ local M = {}

local defaults = {
adapters = {
anthropic = require("codecompanion.adapters").use("anthropic"),
ollama = require("codecompanion.adapters").use("ollama"),
openai = require("codecompanion.adapters").use("openai"),
anthropic = "anthropic",
ollama = "ollama",
openai = "openai",
},
strategies = {
chat = "openai",
Expand Down Expand Up @@ -68,11 +68,15 @@ M.setup = function(opts)
if opts and opts.adapters then
for name, adapter in pairs(opts.adapters) do
if M.options.adapters[name] then
if adapter.schema then
M.options.adapters[name].schema =
vim.tbl_deep_extend("force", M.options.adapters[name].schema, adapter.schema)
if type(adapter) == "string" then
M.options.adapters[name] = require("codecompanion.adapters").use(adapter)
elseif type(adapter) == "table" then
M.options.adapters[name] = adapter
if adapter.schema then
M.options.adapters[name].schema =
vim.tbl_deep_extend("force", M.options.adapters[name].schema, adapter.schema)
end
end
M.options.adapters[name] = adapter
end
end
end
Expand Down

0 comments on commit 12fd54c

Please sign in to comment.