Get it to work with mistral #1570
-
Thank you for this amazing plugin - unfortunately I didn't get it to work yet. Has anyone managed to create a working config for working with mistral? So far I have: return {
"yetone/avante.nvim",
event = "VeryLazy",
version = false, -- Set this to "*" to always pull the latest release version, or set it to false to update to the latest code changes.
provider = "mistral", -- "claude" or "openai" or "azure"
vendors = {
mistral = {
api_key_name = "MISTRAL_API_KEY",
endpoint = "https://api.mistral.ai/v1/chat/completions",
model = "mistral-large-latest",
parse_curl_args = function(opts, code_opts)
local headers = {
["Content-Type"] = "application/json",
["Accept"] = "application/json",
["Authorization"] = "Bearer " .. os.getenv(opts.api_key_name),
}
local Llm = require("avante.providers")
return {
url = opts.endpoint,
-- timeout = base.timeout,
insecure = false,
headers = headers,
body = vim.tbl_deep_extend("force", {
model = opts.model,
temperature = 0,
topK = -1,
topP = -1,
maxTokensToSample = 4000,
stream = true,
messages = Llm.openai.parse_messages(code_opts)
}, {}),
}
end,
parse_response_data = function(data_stream, event_state, opts)
local Llm = require("avante.providers")
Llm.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 = {
"nvim-treesitter/nvim-treesitter",
"stevearc/dressing.nvim",
"nvim-lua/plenary.nvim",
"MunifTanjim/nui.nvim",
--- The below dependencies are optional,
"echasnovski/mini.pick", -- for file_selector provider mini.pick
"nvim-telescope/telescope.nvim", -- for file_selector provider telescope
"hrsh7th/nvim-cmp", -- autocompletion for avante commands and mentions
"ibhagwan/fzf-lua", -- for file_selector provider fzf
"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" },
},
},
config = function()
require('avante').setup()
end
} When I ask, I get the following error: It looks like it is using a claude model, rather than mistral. I got inspiration from #161. Something tells me that it is the |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 13 replies
-
It looks like you are using lazy.nvim. You didn't set it correctly. return {
"yetone/avante.nvim",
event = "VeryLazy",
version = false, -- Set this to "*" to always pull the latest release version, or set it to false to update to the latest code changes.
+ opts = {
provider = "mistral", -- "claude" or "openai" or "azure"
vendors = {
mistral = {
api_key_name = "MISTRAL_API_KEY",
endpoint = "https://api.mistral.ai/v1/chat/completions",
model = "mistral-large-latest",
parse_curl_args = function(opts, code_opts)
local headers = {
["Content-Type"] = "application/json",
["Accept"] = "application/json",
["Authorization"] = "Bearer " .. os.getenv(opts.api_key_name)
}
local Llm = require("avante.providers")
return {
url = opts.endpoint,
-- timeout = base.timeout,
insecure = false,
headers = headers,
body = vim.tbl_deep_extend(
"force",
{
model = opts.model,
temperature = 0,
topK = -1,
topP = -1,
maxTokensToSample = 4000,
stream = true,
messages = Llm.openai.parse_messages(code_opts)
},
{}
)
}
end,
parse_response_data = function(data_stream, event_state, opts)
local Llm = require("avante.providers")
Llm.openai.parse_response(data_stream, event_state, opts)
end
}
}
+ },
build = "make",
dependencies = {
"nvim-treesitter/nvim-treesitter",
"stevearc/dressing.nvim",
"nvim-lua/plenary.nvim",
"MunifTanjim/nui.nvim",
--- The below dependencies are optional,
"echasnovski/mini.pick", -- for file_selector provider mini.pick
"nvim-telescope/telescope.nvim", -- for file_selector provider telescope
"hrsh7th/nvim-cmp", -- autocompletion for avante commands and mentions
"ibhagwan/fzf-lua", -- for file_selector provider fzf
"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"}
}
},
- config = function()
- require("avante").setup()
- end
}
|
Beta Was this translation helpful? Give feedback.
-
Not there yet, but thanks for the reply. I have this now: return {
"yetone/avante.nvim",
-- event = "VeryLazy",
version = false, -- Set this to "*" to always pull the latest release version, or set it to false to update to the latest code changes.
opts = {
provider = "mistral", -- "claude" or "openai" or "azure"
vendors = {
mistral = {
api_key_name = "MISTRAL_API_KEY",
endpoint = "https://api.mistral.ai/v1/chat/completions",
model = "mistral-large-latest",
parse_curl_args = function(opts, code_opts)
local headers = {
["Content-Type"] = "application/json",
["Accept"] = "application/json",
["Authorization"] = "Bearer " .. os.getenv(opts.api_key_name)
}
local Llm = require("avante.providers")
return {
url = opts.endpoint,
-- timeout = base.timeout,
insecure = false,
headers = headers,
body = vim.tbl_deep_extend(
"force",
{
model = opts.model,
temperature = 0,
topK = -1,
topP = -1,
maxTokensToSample = 4000,
stream = true,
messages = Llm.openai.parse_messages(code_opts)
},
{}
)
}
end,
parse_response = function(data_stream, event_state, opts)
local Llm = require("avante.providers")
Llm.openai.parse_response(data_stream, event_state, opts)
end
}
}
},
build = "make",
dependencies = {
"nvim-treesitter/nvim-treesitter",
"stevearc/dressing.nvim",
"nvim-lua/plenary.nvim",
"MunifTanjim/nui.nvim",
--- The below dependencies are optional,
"echasnovski/mini.pick", -- for file_selector provider mini.pick
"nvim-telescope/telescope.nvim", -- for file_selector provider telescope
"hrsh7th/nvim-cmp", -- autocompletion for avante commands and mentions
"ibhagwan/fzf-lua", -- for file_selector provider fzf
"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"}
}
},
} In another issue someone suggested https://github.com/olimorris/codecompanion.nvim/ which works for me, so it's not an issue with the API key |
Beta Was this translation helpful? Give feedback.
-
I've got an error using mistral provider like this
I already followed the marked answer config, but I still got that error |
Beta Was this translation helpful? Give feedback.
-
This is because mistral api doesn't support max_completion_tokens. To resolve that, simply add provider = "mistral",
vendors = {
mistral= {
__inherited_from = "openai",
api_key_name = "MISTRAL_API_KEY",
endpoint = "https://api.mistral.ai/v1/",
model = "mistral-large-latest",
+ max_tokens = 4096, -- to avoid using max_completion_tokens
},
}, |
Beta Was this translation helpful? Give feedback.
All you need is inherit: