dotfiles/nvim/lua/custom/plugins/codecompanion.lua

94 lines
2.9 KiB
Lua
Raw Permalink Normal View History

-- AI-powered coding
-- https://github.com/olimorris/codecompanion.nvim
return {
'olimorris/codecompanion.nvim',
dependencies = {
'nvim-lua/plenary.nvim',
'nvim-treesitter/nvim-treesitter',
'hrsh7th/nvim-cmp', -- Optional: For using slash commands and variables in the chat buffer
'nvim-telescope/telescope.nvim', -- Optional: For using slash commands
{ 'stevearc/dressing.nvim', opts = {} }, -- Optional: Improves the default Neovim UI
},
keys = {
{ '<leader>aa', '<cmd>CodeCompanionActions<CR>', desc = 'Actions' },
{ '<leader>at', '<cmd>CodeCompanionToggle<CR>', desc = 'Toggle chat' },
{ '<leader>aA', '<cmd>CodeCompanionAdd<CR>', desc = 'Add to chat', mode = 'v' },
{ '<leader>ax', '<cmd>CodeCompanion /explain<CR>', desc = 'Explain', mode = '' },
{ '<leader>af', '<cmd>CodeCompanion /fix<CR>', desc = 'Fix', mode = 'v' },
},
config = function()
require('codecompanion').setup {
strategies = {
chat = {
adapter = 'codellama_direct',
},
inline = {
adapter = 'codellama_direct',
},
agent = {
adapter = 'codellama_direct',
},
},
adapters = {
-- Not working yet to go through openwebui. Only works when connecting directly to ollama.
ollama = function()
return require('codecompanion.adapters').extend('ollama', {
env = {
url = 'https://openwebui.grosinger.net/ollama',
api_key = 'cmd:cat /home/tgrosinger/.openwebui',
},
headers = {
['Content-Type'] = 'application/json',
['Authorization'] = 'Bearer ${api_key}',
},
parameters = {
sync = true,
},
schema = {
model = {
default = 'codellama:13b',
},
},
})
end,
codellama_direct = function()
return require('codecompanion.adapters').extend('ollama', {
env = {
url = 'http://192.168.1.66:11434',
},
headers = {
['Content-Type'] = 'application/json',
},
parameters = {
sync = true,
},
schema = {
model = {
default = 'codellama:13b',
},
},
})
end,
llama31_direct = function()
return require('codecompanion.adapters').extend('ollama', {
env = {
url = 'http://192.168.1.66:11434',
},
headers = {
['Content-Type'] = 'application/json',
},
parameters = {
sync = true,
},
schema = {
model = {
default = 'llama3.1:latest',
},
},
})
end,
},
}
end,
}