一、软件介绍
文末提供程序和源码下载学习
avante.nvim 是一个 Neovim 插件,旨在模拟 Cursor AI IDE 的行为。它为用户提供了 AI 驱动的代码建议,并能够以最少的工作量将这些建议直接应用于其源文件
二、软件特征
- AI 驱动的代码帮助 :与 AI 交互,询问有关您当前代码文件的问题,并获得有关改进或修改的智能建议。
- 一键式应用程序 :使用单个命令将 AI 的建议更改快速应用于您的源代码,从而简化编辑过程并节省时间。
三、安装
对于构建二进制文件,如果您希望从源代码构建,则需要 cargo
。否则,curl
和 tar
将用于从 GitHub 获取预构建的二进制文件(文末提供便捷下载)。
lazy.nvim (推荐)
{
"yetone/avante.nvim",
event = "VeryLazy",
version = false, -- Never set this value to "*"! Never!
opts = {
-- add any opts here
-- for example
provider = "openai",
openai = {
endpoint = "https://api.openai.com/v1",
model = "gpt-4o", -- your desired model (or use gpt-4o, etc.)
timeout = 30000, -- Timeout in milliseconds, increase this for reasoning models
temperature = 0,
max_tokens = 8192, -- Increase this to include reasoning tokens (for reasoning models)
--reasoning_effort = "medium", -- low|medium|high, only used for reasoning models
},
},
-- 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" },
},
},
}
vim-plug vim-plug 插件
local add, later, now = MiniDeps.add, MiniDeps.later, MiniDeps.now add({ source = 'yetone/avante.nvim', monitor = 'main', depends = { 'nvim-treesitter/nvim-treesitter', 'stevearc/dressing.nvim', 'nvim-lua/plenary.nvim', 'MunifTanjim/nui.nvim', 'echasnovski/mini.icons' }, hooks = { post_checkout = function() vim.cmd('make') end } }) --- optional add({ source = 'hrsh7th/nvim-cmp' }) add({ source = 'zbirenbaum/copilot.lua' }) add({ source = 'HakonHarnes/img-clip.nvim' }) add({ source = 'MeanderingProgrammer/render-markdown.nvim' }) later(function() require('render-markdown').setup({...}) end) later(function() require('img-clip').setup({...}) -- config img-clip require("copilot").setup({...}) -- setup copilot to your liking require("avante").setup({...}) -- config for avante.nvim end)
packer包装
-- Required plugins use 'nvim-treesitter/nvim-treesitter' use 'stevearc/dressing.nvim' use 'nvim-lua/plenary.nvim' use 'MunifTanjim/nui.nvim' use 'MeanderingProgrammer/render-markdown.nvim' -- Optional dependencies use 'hrsh7th/nvim-cmp' use 'nvim-tree/nvim-web-devicons' -- or use 'echasnovski/mini.icons' use 'HakonHarnes/img-clip.nvim' use 'zbirenbaum/copilot.lua' -- Avante.nvim with build process use { 'yetone/avante.nvim', branch = 'main', run = 'make', config = function() require('avante').setup() end }
Home Manager 家庭管理器
programs.neovim = { plugins = [ { plugin = pkgs.vimPlugins.avante-nvim; type = "lua"; config = '' require("avante_lib").load() require("avante").setup() '' # or builtins.readFile ./plugins/avante.lua; } ]; };
Nixvim
plugins.avante.enable = true;
plugins.avante.settings = {
# setup options here
};
Lua 月亮
-- deps:
require('cmp').setup ({
-- use recommended settings from above
})
require('img-clip').setup ({
-- use recommended settings from above
})
require('copilot').setup ({
-- use recommended settings from above
})
require('render-markdown').setup ({
-- use recommended settings from above
})
require('avante').setup ({
-- Your config here!
})
Default configuration 默认配置
{
---@alias Provider "claude" | "openai" | "azure" | "gemini" | "cohere" | "copilot" | string
provider = "claude", -- The provider used in Aider mode or in the planning phase of Cursor Planning Mode
-- WARNING: Since auto-suggestions are a high-frequency operation and therefore expensive,
-- currently designating it as `copilot` provider is dangerous because: https://github.com/yetone/avante.nvim/issues/1048
-- Of course, you can reduce the request frequency by increasing `suggestion.debounce`.
auto_suggestions_provider = "claude",
cursor_applying_provider = nil, -- The provider used in the applying phase of Cursor Planning Mode, defaults to nil, when nil uses Config.provider as the provider for the applying phase
claude = {
endpoint = "https://api.anthropic.com",
model = "claude-3-5-sonnet-20241022",
temperature = 0,
max_tokens = 4096,
},
---Specify the special dual_boost mode
---1. enabled: Whether to enable dual_boost mode. Default to false.
---2. first_provider: The first provider to generate response. Default to "openai".
---3. second_provider: The second provider to generate response. Default to "claude".
---4. prompt: The prompt to generate response based on the two reference outputs.
---5. timeout: Timeout in milliseconds. Default to 60000.
---How it works:
--- When dual_boost is enabled, avante will generate two responses from the first_provider and second_provider respectively. Then use the response from the first_provider as provider1_output and the response from the second_provider as provider2_output. Finally, avante will generate a response based on the prompt and the two reference outputs, with the default Provider as normal.
---Note: This is an experimental feature and may not work as expected.
dual_boost = {
enabled = false,
first_provider = "openai",
second_provider = "claude",
prompt = "Based on the two reference outputs below, generate a response that incorporates elements from both but reflects your own judgment and unique perspective. Do not provide any explanation, just give the response directly. Reference Output 1: [{{provider1_output}}], Reference Output 2: [{{provider2_output}}]",
timeout = 60000, -- Timeout in milliseconds
},
behaviour = {
auto_suggestions = false, -- Experimental stage
auto_set_highlight_group = true,
auto_set_keymaps = true,
auto_apply_diff_after_generation = false,
support_paste_from_clipboard = false,
minimize_diff = true, -- Whether to remove unchanged lines when applying a code block
enable_token_counting = true, -- Whether to enable token counting. Default to true.
enable_cursor_planning_mode = false, -- Whether to enable Cursor Planning Mode. Default to false.
enable_claude_text_editor_tool_mode = false, -- Whether to enable Claude Text Editor Tool Mode.
},
mappings = {
--- @class AvanteConflictMappings
diff = {
ours = "co",
theirs = "ct",
all_theirs = "ca",
both = "cb",
cursor = "cc",
next = "]x",
prev = "[x",
},
suggestion = {
accept = "<M-l>",
next = "<M-]>",
prev = "<M-[>",
dismiss = "<C-]>",
},
jump = {
next = "]]",
prev = "[[",
},
submit = {
normal = "<CR>",
insert = "<C-s>",
},
cancel = {
normal = { "<C-c>", "<Esc>", "q" },
insert = { "<C-c>" },
},
sidebar = {
apply_all = "A",
apply_cursor = "a",
retry_user_request = "r",
edit_user_request = "e",
switch_windows = "<Tab>",
reverse_switch_windows = "<S-Tab>",
remove_file = "d",
add_file = "@",
close = { "<Esc>", "q" },
close_from_input = nil, -- e.g., { normal = "<Esc>", insert = "<C-d>" }
},
},
hints = { enabled = true },
windows = {
---@type "right" | "left" | "top" | "bottom"
position = "right", -- the position of the sidebar
wrap = true, -- similar to vim.o.wrap
width = 30, -- default % based on available width
sidebar_header = {
enabled = true, -- true, false to enable/disable the header
align = "center", -- left, center, right for title
rounded = true,
},
input = {
prefix = "> ",
height = 8, -- Height of the input window in vertical layout
},
edit = {
border = "rounded",
start_insert = true, -- Start insert mode when opening the edit window
},
ask = {
floating = false, -- Open the 'AvanteAsk' prompt in a floating window
start_insert = true, -- Start insert mode when opening the ask window
border = "rounded",
---@type "ours" | "theirs"
focus_on_apply = "ours", -- which diff to focus after applying
},
},
highlights = {
---@type AvanteConflictHighlights
diff = {
current = "DiffText",
incoming = "DiffAdd",
},
},
--- @class AvanteConflictUserConfig
diff = {
autojump = true,
---@type string | fun(): any
list_opener = "copen",
--- Override the 'timeoutlen' setting while hovering over a diff (see :help timeoutlen).
--- Helps to avoid entering operator-pending mode with diff mappings starting with `c`.
--- Disable by setting to -1.
override_timeoutlen = 500,
},
suggestion = {
debounce = 600,
throttle = 600,
},
}
四、lua月亮
Lua 月亮
file_selector = {
--- @alias FileSelectorProvider "native" | "fzf" | "mini.pick" | "snacks" | "telescope" | string | fun(params: avante.file_selector.IParams|nil): nil
provider = "fzf",
-- Options override for custom providers
provider_opts = {},
}
To create a customized file_selector, you can specify a customized function to launch a picker to select items and pass the selected items to the handler callback.
要创建自定义 file_selector,您可以指定自定义函数来启动选取器以选择项目并将所选项目传递给处理程序回调。
file_selector = {
---@param params avante.file_selector.IParams
provider = function(params)
local filepaths = params.filepaths ---@type string[]
local title = params.title ---@type string
local handler = params.handler ---@type fun(selected_filepaths: string[]|nil): nil
-- Launch your customized picker with the items built from `filepaths`, then in the `on_confirm` callback,
-- pass the selected items (convert back to file paths) to the `handler` function.
local items = __your_items_formatter__(filepaths)
__your_picker__({
items = items,
on_cancel = function()
handler(nil)
end,
on_confirm = function(selected_items)
local selected_filepaths = {}
for _, item in ipairs(selected_items) do
table.insert(selected_filepaths, item.filepath)
end
handler(selected_filepaths)
end
})
end,
---below is optional
provider_opts = {
---@param params avante.file_selector.opts.IGetFilepathsParams
get_filepaths = function(params)
local cwd = params.cwd ---@type string
local selected_filepaths = params.selected_filepaths ---@type string[]
local cmd = string.format("fd --base-directory '%s' --hidden", vim.fn.fnameescape(cwd))
local output = vim.fn.system(cmd)
local filepaths = vim.split(output, "\n", { trimempty = true })
return vim
.iter(filepaths)
:filter(function(filepath)
return not vim.tbl_contains(selected_filepaths, filepath)
end)
:totable()
end
}
end
}
Choose a selector other that native, the default as that currently has an issue For lazyvim users copy the full config for blink.cmp from the website or extend the options
选择本机以外的选择器,默认选择器当前有问题 对于 lazyvim 用户,请从网站复制 blink.cmp 的完整配置或扩展选项
compat = {
"avante_commands",
"avante_mentions",
"avante_files",
}
For other users just add a custom provider
对于其他用户,只需添加自定义提供程序
default = {
...
"avante_commands",
"avante_mentions",
"avante_files",
}
providers = {
avante_commands = {
name = "avante_commands",
module = "blink.compat.source",
score_offset = 90, -- show at a higher priority than lsp
opts = {},
},
avante_files = {
name = "avante_files",
module = "blink.compat.source",
score_offset = 100, -- show at a higher priority than lsp
opts = {},
},
avante_mentions = {
name = "avante_mentions",
module = "blink.compat.source",
score_offset = 1000, -- show at a higher priority than lsp
opts = {},
}
...
}
重要
为了 neovim session 之间的最大一致性,建议在 shell 文件中设置环境变量。默认情况下,Avante
会在启动时提示您输入所选提供商的 API 密钥。
For Claude: 对于 Claude:
export ANTHROPIC_API_KEY=your-api-key
For OpenAI: 对于 OpenAI:
export OPENAI_API_KEY=your-api-key
For Azure OpenAI: 对于 Azure OpenAI:
export AZURE_OPENAI_API_KEY=your-api-key
For Amazon Bedrock: 对于 Amazon Bedrock:
export BEDROCK_KEYS=aws_access_key_id,aws_secret_access_key,aws_region[,aws_session_token]
Note: The aws_session_token is optional and only needed when using temporary AWS credentials
注意:aws_session_token 是可选的,仅在使用临时 AWS 凭证时才需要
- Open a code file in Neovim.
在 Neovim 中打开一个代码文件。 - Use the
:AvanteAsk
command to query the AI about the code.
使用:AvanteAsk
命令向 AI 查询有关代码的信息。 - Review the AI's suggestions.
查看 AI 的建议。 - Apply the recommended changes directly to your code with a simple command or key binding.
使用简单的命令或键绑定将建议的更改直接应用于您的代码。
Note: The plugin is still under active development, and both its functionality and interface are subject to significant changes. Expect some rough edges and instability as the project evolves.
注意 :该插件仍在积极开发中,其功能和界面都会发生重大变化。随着项目的发展,预计会有一些粗糙的边缘和不稳定。
五、Key Bindings 键绑定
以下键绑定可用于 avante.nvim
:
Key Binding 密钥绑定 | Description 描述 |
---|---|
Leaderaa | show sidebar 显示侧边栏 |
Leaderat | toggle sidebar visibility 切换侧边栏可见性 |
Leaderar | refresh sidebar 刷新边栏 |
Leaderaf | switch sidebar focus 切换侧边栏焦点 |
Leadera? | select model 选择型号 |
Leaderae | edit selected blocks 编辑所选块 |
LeaderaS | stop current AI request 停止当前 AI 请求 |
co | choose ours 选择我们的 |
ct | choose theirs 选择他们的 |
ca | choose all theirs 选择他们所有的 |
c0 | choose none 选择无 |
cb | choose both 选择两者 |
cc | choose cursor 选择光标 |
]x | move to previous conflict 移至上一个冲突 |
[x | move to next conflict 移至下一个冲突 |
[[ | jump to previous codeblocks (results window) 跳转到上一个代码块(Results 窗口) |
]] | jump to next codeblocks (results windows) 跳至下一个代码块(结果窗口) |
快捷方式
在 neotree 侧边栏中,您还可以添加新的键盘快捷键,以快速将文件/文件夹添加到 Avante Selected Files。
Neotree configuration Neotree 配置
return {
{
'nvim-neo-tree/neo-tree.nvim',
config = function()
require('neo-tree').setup({
filesystem = {
commands = {
avante_add_files = function(state)
local node = state.tree:get_node()
local filepath = node:get_id()
local relative_path = require('avante.utils').relative_path(filepath)
local sidebar = require('avante').get()
local open = sidebar:is_open()
-- ensure avante sidebar is open
if not open then
require('avante.api').ask()
sidebar = require('avante').get()
end
sidebar.file_selector:add_selected_file(relative_path)
-- remove neo tree buffer
if not open then
sidebar.file_selector:remove_selected_file('neo-tree filesystem [1]')
end
end,
},
window = {
mappings = {
['oa'] = 'avante_add_files',
},
},
},
})
end,
},
}
Commands 命令
Commands 命令
Command 命令 | Description 描述 | Examples 例子 |
---|---|---|
:AvanteAsk [question] [position] | Ask AI about your code. Optional position set window position and ask enable/disable direct asking mode向 AI 询问您的代码。可选 位置 设置窗口位置和询问 启用/禁用直接询问模式 | :AvanteAsk position=right Refactor this code here |
:AvanteBuild :AvanteBuild | Build dependencies for the project 构建项目的依赖项 | |
:AvanteChat :AvanteChat | Start a chat session with AI about your codebase. Default is ask =false开始与 AI 就您的代码库进行聊天。默认值为 ask =false | |
:AvanteClear :AvanteClear | Clear the chat history 清除聊天记录 | |
:AvanteEdit :Avante 编辑 | Edit the selected code blocks 编辑选定的代码块 | |
:AvanteFocus :AvanteFocus | Switch focus to/from the sidebar 将焦点切换到侧边栏或从侧边栏切换焦点 | |
:AvanteRefresh :AvanteRefresh | Refresh all Avante windows 刷新所有 Avante 窗口 | |
:AvanteStop :AvanteStop | Stop the current AI request 停止当前 AI 请求 | |
:AvanteSwitchProvider :AvanteSwitchProvider | Switch AI provider (e.g. openai) Switch AI 提供商(例如 openai) | |
:AvanteShowRepoMap - 模板:ShowRepoMap | Show repo map for project's structure 显示项目结构的存储库映射 | |
:AvanteToggle :AvanteToggle | Toggle the Avante sidebar 切换 Avante 侧边栏 | |
:AvanteModels :AvanteModels | Show model list 显示型号列表 |
Highlight Groups 高亮显示组
Highlight Group 高光组 | Description 描述 | Notes 笔记 |
---|---|---|
AvanteTitle Avante 标题 | Title 标题 | |
AvanteReversedTitle | Used for rounded border 用于圆角边框 | |
AvanteSubtitle Avante 字幕 | Selected code title 选定的代码标题 | |
AvanteReversedSubtitle AvanteReversed 字幕 | Used for rounded border 用于圆角边框 | |
AvanteThirdTitle 在他的对立面 | Prompt title 提示标题 | |
AvanteReversedThirdTitle | Used for rounded border 用于圆角边框 | |
AvanteConflictCurrent | Current conflict highlight 当前冲突突出显示 | Default to Config.highlights.diff.current 默认为 Config.highlights.diff.current |
AvanteConflictIncoming ForwardConflictIncoming | Incoming conflict highlight 传入冲突高亮显示 | Default to Config.highlights.diff.incoming 默认为 Config.highlights.diff.incoming |
AvanteConflictCurrentLabel | Current conflict label highlight 当前冲突标签高亮显示 | Default to shade of AvanteConflictCurrent 默认为 AvanteConflictCurrent 的阴影 |
AvanteConflictIncomingLabel ForwardConflictIncomingLabel | Incoming conflict label highlight 传入冲突标签高亮显示 | Default to shade of AvanteConflictIncoming 默认为 AvanteConflictIncoming 的阴影 |
AvantePopupHint AvantePopup 提示 | Usage hints in popup menus 弹出菜单中的使用提示 | |
AvanteInlineHint AvanteInline 提示 | The end-of-line hint displayed in visual mode 以可视模式显示的行尾提示 |
Ollama 奥拉马
OLLAMA 是 AVANTE.NVIM 的一流提供商。您可以通过在配置中设置 provider = “ollama”
来使用它,并将 ollama
中的 model
字段设置为您要使用的模型。例如:
provider = "ollama",
ollama = {
model = "qwq:32b",
}
AiHubMix
AiHubMix 是 avante.nvim 的内置提供程序。你可以在 AiHubMix 官网注册一个账号,然后在网站内创建一个 API Key,并在你的环境变量中设置这个 API Key:
export AIHUBMIX_API_KEY=your_api_key
Then in your configuration, set provider = "aihubmix", and set the model field to the model name you want to use, for example:
然后在您的配置中,设置 provider = “aihubmix”,并将 model 字段设置为您要使用的模型名称,例如:
provider = "aihubmix",
aihubmix = {
model = "gpt-4o-2024-11-20",
}
Cursor planning mode 光标规划模式
因为 avante.nvim 一直使用 Aider 的方法进行规划申请,但是它的提示符对模型非常挑剔,需要像 claude-3.5-sonnet 或 gpt-4o 这样的模型才能正常工作。
RAG Service RAG 服务
Avante 提供 RAG 服务,该服务是获取 AI 生成代码所需上下文的工具。默认情况下,它未启用。您可以通过以下方式启用它:
rag_service = {
enabled = false, -- Enables the RAG service
host_mount = os.getenv("HOME"), -- Host mount path for the rag service
provider = "openai", -- The provider to use for RAG service (e.g. openai or ollama)
llm_model = "", -- The LLM model to use for RAG service
embed_model = "", -- The embedding model to use for RAG service
endpoint = "https://api.openai.com/v1", -- The API endpoint for RAG service
},
If your rag_service provider is openai
, then you need to set the OPENAI_API_KEY
environment variable!
如果你的 rag_service 提供商是 openai
,那么你需要设置 OPENAI_API_KEY
环境变量!
If your rag_service provider is ollama
, you need to set the endpoint to http://localhost:11434
(note there is no /v1
at the end) or any address of your own ollama server.
如果您的 rag_service 提供商是 ollama
,则需要将端点设置为 http://localhost:11434
(注意末尾没有 /v1
)或您自己的 ollama 服务器的任何地址。
If your rag_service provider is ollama
, when llm_model
is empty, it defaults to llama3
, and when embed_model
is empty, it defaults to nomic-embed-text
. Please make sure these models are available in your ollama server.
如果您的 rag_service 提供程序是 ollama
,则当 llm_model
为空时,默认为 llama3
,当 embed_model
为空时,默认为 nomic-embed-text
。请确保您的 ollama 服务器中提供了这些模型。
Additionally, RAG Service also depends on Docker! (For macOS users, OrbStack is recommended as a Docker alternative).
此外,RAG 服务也依赖于 Docker!(对于 macOS 用户,建议使用 OrbStack 作为 Docker 替代方案)。
host_mount
is the path that will be mounted to the container, and the default is the home directory. The mount is required for the RAG service to access the files in the host machine. It is up to the user to decide if you want to mount the whole /
directory, just the project directory, or the home directory. If you plan using avante and RAG event for projects stored outside your home directory, you will need to set the host_mount
to the root directory of your file system.
host_mount
是将挂载到容器的路径,默认是主目录。安装是必需的 供 RAG 服务访问主机中的文件。由用户决定是否要挂载整个 /
目录下,仅项目目录或主目录。如果您计划对存储在主目录之外的项目使用 avante 和 RAG 事件,则需要将 host_mount
设置为文件系统的根目录。
The mount will be read only.
挂载将为只读。
After changing the rag_service configuration, you need to manually delete the rag_service container to ensure the new configuration is used: docker rm -fv avante-rag-service
更改 rag_service 配置后,您需要手动删除 rag_service 容器,以确保使用新的配置: docker rm -fv avante-rag-service
Web Search Engines Web 搜索引擎
Avante 的工具包括一些网络搜索引擎,目前支持:
Tavily 塔维利
SerpApi SerpApi 的
SearchAPI 搜索 API
Google's Programmable Search Engine
Google 的可编程搜索引擎
Kagi 卡吉
Brave Search 勇敢的搜索
SearXNG SearXNG 系列
默认值为 Tavily,可以通过配置 Config.web_search_engine.provider
来更改:
web_search_engine = {
provider = "tavily", -- tavily, serpapi, searchapi, google, kagi, brave, or searxng
proxy = nil, -- proxy support, e.g., http://127.0.0.1:7890
}
Environment variables required for providers:
提供程序所需的环境变量:
- Tavily:
TAVILY_API_KEY
塔维利:TAVILY_API_KEY
- SerpApi:
SERPAPI_API_KEY
SerpApi:SERPAPI_API_KEY
- SearchAPI:
SEARCHAPI_API_KEY
搜索 API:SEARCHAPI_API_KEY
- Google: 谷歌:
GOOGLE_SEARCH_API_KEY
as the API key
GOOGLE_SEARCH_API_KEY
作为 API 密钥GOOGLE_SEARCH_ENGINE_ID
as the search engine ID
GOOGLE_SEARCH_ENGINE_ID
作为搜索引擎 ID
- Kagi:
KAGI_API_KEY
as the API Token
Kagi:KAGI_API_KEY
作为 API 令牌 - Brave Search:
BRAVE_API_KEY
as the API key
Brave Search:BRAVE_API_KEY
作为 API 密钥 - SearXNG:
SEARXNG_API_URL
as the API URL
SearXNG:SEARXNG_API_URL
作为 API URL
Disable Tools 禁用工具
Avante 默认启用工具,但某些LLM型号不支持工具。您可以通过为提供程序设置 disable_tools = true
来禁用工具。例如:
{
claude = {
endpoint = "https://api.anthropic.com",
model = "claude-3-5-sonnet-20241022",
timeout = 30000, -- Timeout in milliseconds
temperature = 0,
max_tokens = 4096,
disable_tools = true, -- disable tools!
},
}
In case you want to ban some tools to avoid its usage (like Claude 3.7 overusing the python tool) you can disable just specific tools
如果您想禁止某些工具以避免其使用(例如 Claude 3.7 过度使用 python 工具),您可以仅禁用特定工具
{
disabled_tools = { "python" },
}
Tool list 工具列表
rag_search, python, git_diff, git_commit, list_files, search_files, search_keyword, read_file_toplevel_symbols, read_file, create_file, rename_file, delete_file, create_dir, rename_dir, delete_dir, bash, web_search, fetch
rag_search、python、git_diff、git_commit、list_files、search_files、search_keyword、read_file_toplevel_symbols、read_file、create_file、rename_file、delete_file、create_dir、rename_dir、delete_dir、bash、web_search、fetch
Custom Tools 自定义工具
Avante 允许您定义 AI 在代码生成和分析期间可以使用的自定义工具。这些工具可以执行 shell 命令、运行脚本或执行您需要的任何自定义逻辑。
Example: Go Test Runner 示例:Go Test Runner
Here's an example of a custom tool that runs Go unit tests:
下面是运行 Go 单元测试的自定义工具的示例:
{
custom_tools = {
{
name = "run_go_tests", -- Unique name for the tool
description = "Run Go unit tests and return results", -- Description shown to AI
command = "go test -v ./...", -- Shell command to execute
param = { -- Input parameters (optional)
type = "table",
fields = {
{
name = "target",
description = "Package or directory to test (e.g. './pkg/...' or './internal/pkg')",
type = "string",
optional = true,
},
},
},
returns = { -- Expected return values
{
name = "result",
description = "Result of the fetch",
type = "string",
},
{
name = "error",
description = "Error message if the fetch was not successful",
type = "string",
optional = true,
},
},
func = function(params, on_log, on_complete) -- Custom function to execute
local target = params.target or "./..."
return vim.fn.system(string.format("go test -v %s", target))
end,
},
},
}
MCP
现在,您可以通过 mcphub.nim
为 Avante 集成 MCP 功能。
Claude 文本编辑器工具模式
Avante 利用 Claude 文本编辑器工具提供更优雅的代码编辑体验。您现在可以通过在行为
配置中设置为 enable_claude_text_editor_tool_mode
true
来启用此功能:
{
behaviour = {
enable_claude_text_editor_tool_mode = true,
},
}
Note 注意
To enable Claude Text Editor Tool Mode, you must use the claude-3-5-sonnet-*
or claude-3-7-sonnet-*
model with the claude
provider! This feature is not supported by any other models!
要启用 Claude 文本编辑器工具模式 ,您必须将 claude-3-5-sonnet-*
或 claude-3-7-sonnet-*
模型与 claude
提供程序一起使用!任何其他型号都不支持此功能!
Custom prompts 自定义提示
默认情况下,avante.nvim
提供三种不同的交互模式: 规划
、 编辑
和建议
,每种模式提供三种不同的提示。
planning
: Used withrequire("avante").toggle()
on sidebar
planning
:与侧边栏上的require(“avante”).toggle()
一起使用editing
: Used withrequire("avante").edit()
on selection codeblock
editing
: 与选择代码块上的require(“avante”).edit()
一起使用suggesting
: Used withrequire("avante").get_suggestion():suggest()
on Tab flow.
suggesting
:与require("avante").get_suggestion():suggest()
Tab 流一起使用。cursor-planning
: Used withrequire("avante").toggle()
on Tab flow, but only when cursor planning mode is enabled.
cursor-planning
:与 Tab 流上的require(“avante”).toggle()
一起使用,但仅在启用光标规划模式时。
Users can customize the system prompts via Config.system_prompt
. We recommend calling this in a custom Autocmds depending on your need:
用户可以通过 Config.system_prompt
自定义系统提示。我们建议根据您的需要在自定义 Autocmds 中调用它:
vim.api.nvim_create_autocmd("User", {
pattern = "ToggleMyPrompt",
callback = function() require("avante.config").override({system_prompt = "MY CUSTOM SYSTEM PROMPT"}) end,
})
vim.keymap.set("n", "<leader>am", function() vim.api.nvim_exec_autocmds("User", { pattern = "ToggleMyPrompt" }) end, { desc = "avante: toggle my prompt" })
If one wish to custom prompts for each mode, avante.nvim
will check for project root based on the given buffer whether it contains the following patterns: *.{mode}.avanterules
.
如果希望为每种模式自定义提示,avante.nvim
将根据给定的缓冲区检查项目根是否包含以下模式:*.{mode}.avante 规则
。
The rules for root hierarchy:
根层次结构的规则:
- lsp workspace folders LSP 工作区文件夹
- lsp root_dir
- root pattern of filename of the current buffer
当前缓冲区的 filename 的根模式 - root pattern of cwd CWD 的根型
Example folder structure for custom prompt
自定义提示的文件夹结构示例
Important 重要
*.avanterules
是一个 jinja 模板文件,其中将使用 minijinja 进行渲染。
TODOs 都
- Chat with current file 与当前文件聊天
- Apply diff patch 应用 diff patch
- Chat with the selected block
与所选区块聊天 - Slash commands 斜杠命令
- Edit the selected block 编辑所选块
- Smart Tab (Cursor Flow) 智能选项卡 (光标流)
- Chat with project (You can use
@codebase
to chat with the whole project)
与项目聊天(您可以使用@codebase
与整个项目聊天) - Chat with selected files 与选定的文件聊天
- Tool use 工具使用
- MCP
- Better codebase indexing 更好的代码库索引
Roadmap 路线图
- 增强的 AI 交互 :提高 AI 分析的深度,并为更复杂的编码场景提供建议。
- LSP + Tree-sitter + LLM 集成 :与 LSP 和 Tree-sitter 集成,LLM 提供更准确、更强大的代码建议和分析。
软件下载
本文信息来源于GitHub作者地址:https://github.com/yetone/avante.nvim