Neovim: Add ai coding companion using remote ollama

This commit is contained in:
Tony Grosinger 2024-09-20 10:03:25 -07:00
parent 6022c73977
commit 519d42bbe7
2 changed files with 95 additions and 0 deletions

View File

@ -240,6 +240,7 @@ require('lazy').setup({
-- Document existing key chains
require('which-key').register {
['<leader>a'] = { name = '[A]i', _ = 'which_key_ignore' },
['<leader>c'] = { name = '[C]ode', _ = 'which_key_ignore' },
['<leader>d'] = { name = '[D]ocument', _ = 'which_key_ignore' },
['<leader>r'] = { name = '[R]ename', _ = 'which_key_ignore' },
@ -252,6 +253,7 @@ require('lazy').setup({
}
-- visual mode
require('which-key').register({
['<leader>a'] = { '[A]i' },
['<leader>h'] = { 'Git [H]unk' },
}, { mode = 'v' })
end,

View File

@ -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 = {
{ '<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,
}