Skip to content

Commit

Permalink
feat(config): Allow specifying adapters by string (#13)
Browse files Browse the repository at this point in the history
* feat(config): Allow specifying adapters by string

* update README.md
  • Loading branch information
mrjones2014 authored Mar 8, 2024
1 parent 1814f90 commit 847de14
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ You only need to the call the `setup` function if you wish to change any of the
```lua
require("codecompanion").setup({
adapters = {
chat = require("codecompanion.adapters").use("openai"),
inline = require("codecompanion.adapters").use("openai"),
chat = "openai",
inline = "openai",
},
saved_chats = {
save_dir = vim.fn.stdpath("data") .. "/codecompanion/saved_chats", -- Path to save chats to
Expand Down
9 changes: 9 additions & 0 deletions lua/codecompanion/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ M.setup = function(opts)
}
vim.diagnostic.config(diagnostic_config, M.INFO_NS)
vim.diagnostic.config(diagnostic_config, M.ERROR_NS)

local chat_adapter = vim.tbl_get(M.options, "adapters", "chat")
if type(chat_adapter) == "string" then
M.options.adapters.chat = require("codecompanion.adapters").use(chat_adapter)
end
local inline_adapter = vim.tbl_get(M.options, "adapters", "inline")
if type(inline_adapter) == "string" then
M.options.adapters.inline = require("codecompanion.adapters").use(inline_adapter)
end
end

return M

0 comments on commit 847de14

Please sign in to comment.