bug: Broken Ollama support
Closed this issue · 6 comments
Describe the bug
I followed the instructions for Ollama support as described in the Wiki but it doesn't seem to work. My suspicion is that the Ollama API has changed since then.
I'm running the Docker image for Ollama on localhost and I successfully connected to the Ollama server on port 11434 using telnet.
Here is my setup:
"yetone/avante.nvim",
event = "VeryLazy",
lazy = false,
version = false, -- set this if you want to always pull the latest change
opts = {
provider = "ollama",
vendors = {
---@type AvanteProvider
ollama = {
["local"] = true,
endpoint = "127.0.0.1:11434/v1",
model = "llama3.2",
parse_curl_args = function(opts, code_opts)
return {
url = opts.endpoint .. "/chat/completions",
headers = {
["Accept"] = "application/json",
["Content-Type"] = "application/json",
},
body = {
model = opts.model,
messages = require("avante.providers").copilot.parse_message(code_opts), -- you can make your own message, but this is very advanced
max_tokens = 2048,
stream = true,
},
}
end,
parse_response_data = function(data_stream, event_state, opts)
require("avante.providers").openai.parse_response(data_stream, event_state, opts)
end,
},
},
},
-- if you want to build from source then do `make BUILD_FROM_SOURCE=true`
build = "make",
-- build = "powershell -ExecutionPolicy Bypass -File Build.ps1 -BuildFromSource false" -- for windows
dependencies = {
"stevearc/dressing.nvim",
"nvim-lua/plenary.nvim",
"MunifTanjim/nui.nvim",
--- The below dependencies are optional,
"nvim-tree/nvim-web-devicons", -- or echasnovski/mini.icons
"zbirenbaum/copilot.lua", -- for providers='copilot'
{
-- support for image pasting
"HakonHarnes/img-clip.nvim",
event = "VeryLazy",
opts = {
-- recommended settings
default = {
embed_image_as_base64 = false,
prompt_for_file_name = false,
drag_and_drop = {
insert_mode = true,
},
-- required for Windows users
use_absolute_path = true,
},
},
},
{
-- Make sure to set this up properly if you have lazy=true
'MeanderingProgrammer/render-markdown.nvim',
opts = {
file_types = { "markdown", "Avante" },
},
ft = { "markdown", "Avante" },
},
}
Here is the error message:
E5108: Error executing lua: /home/fakr00n/.config/nvim/lua/custom/plugins.lua:99: attempt to call field 'parse_message' (a nil value)
stack traceback:
/home/fakr00n/.config/nvim/lua/custom/plugins.lua:99: in function 'parse_curl_args'
...0n/.local/share/nvim/lazy/avante.nvim/lua/avante/llm.lua:136: in function 'stream'
...local/share/nvim/lazy/avante.nvim/lua/avante/sidebar.lua:1432: in function 'handle_submit'
...local/share/nvim/lazy/avante.nvim/lua/avante/sidebar.lua:1488: in function <...local/share/nvim/lazy/avante.nvim/lua/avante/sidebar.lua:1478>
To reproduce
No response
Expected behavior
No response
Installation method
Use lazy.nvim:
{
"yetone/avante.nvim",
event = "VeryLazy",
lazy = false,
version = false, -- set this if you want to always pull the latest change
opts = {
-- add any opts here
},
-- if you want to build from source then do `make BUILD_FROM_SOURCE=true`
build = "make",
-- build = "powershell -ExecutionPolicy Bypass -File Build.ps1 -BuildFromSource false" -- for windows
dependencies = {
"nvim-treesitter/nvim-treesitter",
"stevearc/dressing.nvim",
"nvim-lua/plenary.nvim",
"MunifTanjim/nui.nvim",
},
}
Environment
Neovim version: 0.10.2-2
Repro
vim.env.LAZY_STDPATH = ".repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()
require("lazy.minit").repro({
spec = {
-- add any other plugins here
},
})
Thanx! It works now :)
The Wiki should be updated to comply to the new API.
@fakr00n did you have to implement the parse_stream_message
function? That is where I have the issue.
Error executing vim.schedule lua callback: ...ue/.local/share/nvim/lazy/avante.nvim/lua/avante/llm.lua:146: attempt to call field 'parse_response' (a nil value)
stack traceback:
...ue/.local/share/nvim/lazy/avante.nvim/lua/avante/llm.lua:146: in function 'parse_stream_data'
...ue/.local/share/nvim/lazy/avante.nvim/lua/avante/llm.lua:193: in function <...ue/.local/share/nvim/lazy/avante.nvim/lua/avante/llm.lua:180>
@fakr00n did you have to implement the
parse_stream_message
function? That is where I have the issue.Error executing vim.schedule lua callback: ...ue/.local/share/nvim/lazy/avante.nvim/lua/avante/llm.lua:146: attempt to call field 'parse_response' (a nil value) stack traceback: ...ue/.local/share/nvim/lazy/avante.nvim/lua/avante/llm.lua:146: in function 'parse_stream_data' ...ue/.local/share/nvim/lazy/avante.nvim/lua/avante/llm.lua:193: in function <...ue/.local/share/nvim/lazy/avante.nvim/lua/avante/llm.lua:180>
No, I didn't implement anything. I just renamed the function parse_stream_message
to parse_stream_messages
in this line:
messages = require("avante.providers").copilot.parse_message(code_opts), -- you can make your own message, but this is very advanced
in my nvim config file as @ryul99 kindly suggested and it worked for me.
if you take a look at file avante.nvim/lua/avante/providers/copilot.lua:144
the function parse_stream_message
dosn't exist and it seems that it has been renamed to parse_stream_messages
.
They've apparently changed the API without updating the Wiki (see #805) and since the wiki is not part of the Git repo nobody can do a pull request and fix it. Only the owner of the project can, so... I Guess more people will stumble on this issue then :)
There may have been another api change, but now, at least for me, I needed to change
parse_response
to parse_response_data
(judging by what's found here). Here's my working config:
opts = {
provider = 'ollama',
vendors = {
---@type AvanteProvider
ollama = {
['local'] = true,
endpoint = '127.0.0.1:11434/v1',
model = 'codegemma',
parse_response_data = function(data_stream, event_state, opts)
require('avante.providers').copilot.parse_response(data_stream, event_state, opts)
end,
parse_curl_args = function(opts, code_opts)
return {
url = opts.endpoint .. '/chat/completions',
headers = {
['Accept'] = 'application/json',
['Content-Type'] = 'application/json',
},
body = {
model = opts.model,
messages = require('avante.providers').copilot.parse_messages(code_opts),
max_tokens = 2048,
stream = true,
},
}
end,
},
},
},
There may have been another api change, but now, at least for me, I needed to change
parse_response
toparse_response_data
(judging by what's found here). Here's my working config:opts = { provider = 'ollama', vendors = { ---@type AvanteProvider ollama = { ['local'] = true, endpoint = '127.0.0.1:11434/v1', model = 'codegemma', parse_response_data = function(data_stream, event_state, opts) require('avante.providers').copilot.parse_response(data_stream, event_state, opts) end, parse_curl_args = function(opts, code_opts) return { url = opts.endpoint .. '/chat/completions', headers = { ['Accept'] = 'application/json', ['Content-Type'] = 'application/json', }, body = { model = opts.model, messages = require('avante.providers').copilot.parse_messages(code_opts), max_tokens = 2048, stream = true, }, } end, }, }, },
I suggest you to file a new ticket/issue with your findings since this is not really related to this one.
The problem is that the Wiki is not part of the Git repo so no one (except the owner/maintainers) can edit the wiki. This can't unfortunatly be fixed by a pull request.