diff --git a/nvim/init.lua b/nvim/init.lua index c470d22..cff147a 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -240,6 +240,7 @@ require('lazy').setup({ -- Document existing key chains require('which-key').register { + ['a'] = { name = '[A]i', _ = 'which_key_ignore' }, ['c'] = { name = '[C]ode', _ = 'which_key_ignore' }, ['d'] = { name = '[D]ocument', _ = 'which_key_ignore' }, ['r'] = { name = '[R]ename', _ = 'which_key_ignore' }, @@ -252,6 +253,7 @@ require('lazy').setup({ } -- visual mode require('which-key').register({ + ['a'] = { '[A]i' }, ['h'] = { 'Git [H]unk' }, }, { mode = 'v' }) end, diff --git a/nvim/lua/custom/plugins/codecompanion.lua b/nvim/lua/custom/plugins/codecompanion.lua new file mode 100644 index 0000000..33e93c3 --- /dev/null +++ b/nvim/lua/custom/plugins/codecompanion.lua @@ -0,0 +1,93 @@ +-- 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 = { + { 'aa', 'CodeCompanionActions', desc = 'Actions' }, + { 'at', 'CodeCompanionToggle', desc = 'Toggle chat' }, + { 'aA', 'CodeCompanionAdd', desc = 'Add to chat', mode = 'v' }, + { 'ax', 'CodeCompanion /explain', desc = 'Explain', mode = '' }, + { 'af', 'CodeCompanion /fix', 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, +}