Compare commits

...

32 Commits

Author SHA1 Message Date
zhangkun9038@dingtalk.com
15834922c4 merge from upstream 2025-02-17 16:30:34 +08:00
b6ae4dfe7f
fix: use absolute paths to handle gitignore
Co-authored-by: zhangkun9038@dingtalk.com <zhangkun9038@dingtalk.com>
2025-02-17 12:56:09 +08:00
8uff3r
f70eb1040c
fix(providers/openai): check for vim.NIl on tool_calls (#1283) 2025-02-17 12:54:58 +08:00
kyrisu
6fd82f24dd
fix: correct typo in answer field name in tavily format_response_body function (#1287) 2025-02-17 12:53:15 +08:00
Enes Kutay SEZEN
0a146dc63a
docs: add reasoning_effort docs (#1286) 2025-02-17 12:52:22 +08:00
zhangkun9038@dingtalk.com
954709ef3f try 2025-02-15 18:50:20 +08:00
zhangkun9038@dingtalk.com
f7205c3e5a show provider selector 2025-02-14 18:31:39 +08:00
zhangkun9038@dingtalk.com
1ce3efbfe6 show provider selector 2025-02-14 12:42:51 +08:00
zhangkun9038@dingtalk.com
c8460ca574 remove logs 2025-02-14 00:17:02 +08:00
zhangkun9038@dingtalk.com
2086f7d9bc response to log 2025-02-13 13:56:42 +08:00
zhangkun9038@dingtalk.com
0e142811f4 response to log 2025-02-13 13:44:24 +08:00
zhangkun9038@dingtalk.com
481bed92cd baid appid remove hardcode 2025-02-13 11:12:02 +08:00
zhangkun9038@dingtalk.com
3e94b5bd0c baid appid remove hardcode 2025-02-13 11:05:07 +08:00
1be1c2bbbd up 2025-02-13 03:21:29 +08:00
545a8419a7 参数化百度 appid 2025-02-13 02:56:36 +08:00
zhangkun9038@dingtalk.com
79ded43408 add baidu 2025-02-13 00:41:25 +08:00
zhangkun9038@dingtalk.com
7daed04ff5 add baidu 2025-02-13 00:04:19 +08:00
zhangkun9038@dingtalk.com
71ac22a864 add baidu 2025-02-12 23:47:03 +08:00
zhangkun9038@dingtalk.com
ab9127fcbc remove baidu 2025-02-12 22:38:55 +08:00
zhangkun9038@dingtalk.com
4d9201bbea up 2025-02-11 11:01:16 +08:00
zhangkun9038@dingtalk.com
58375d45c3 up 2025-02-11 10:32:29 +08:00
zhangkun9038@dingtalk.com
8472880c89 revert config.lua 2025-02-11 02:01:49 +08:00
zhangkun9038@dingtalk.com
47e23787e5 custome 2025-02-11 01:46:29 +08:00
zhangkun9038@dingtalk.com
56cf5b5bee try add baidu 2025-02-10 11:58:06 +08:00
zhangkun9038@dingtalk.com
676e1194b1 Reset code state to commit e70b0fa243bb8ac07cfc7892f4722e433aa996cb 2025-02-10 02:38:38 +08:00
zhangkun9038@dingtalk.com
7d021f92bb add baidu 2025-02-09 23:59:10 +08:00
zhangkun9038@dingtalk.com
07abe12f54 add request log 2025-02-09 22:17:25 +08:00
zhangkun9038@dingtalk.com
be74f25b82 support baidu bce 2025-02-09 21:42:25 +08:00
zhangkun9038@dingtalk.com
3d639b9eaf Reset code state to origin 2025-02-09 21:06:13 +08:00
zhangkun9038@dingtalk.com
a715664408 add baidu bce platform support 2025-02-09 02:02:11 +08:00
zhangkun9038@dingtalk.com
3f61df6373 add baidu bce platform support 2025-02-09 01:47:25 +08:00
zhangkun9038@dingtalk.com
d407caa8c5 forked 2025-02-09 01:10:23 +08:00
10 changed files with 315 additions and 7 deletions

View File

@ -60,6 +60,7 @@ For building binary if you wish to build from source, then `cargo` is required.
timeout = 30000, -- timeout in milliseconds
temperature = 0, -- adjust if needed
max_tokens = 4096,
reasoning_effort = "high" -- only supported for "o" models
},
},
-- if you want to build from source then do `make BUILD_FROM_SOURCE=true`

View File

@ -36,7 +36,7 @@ M._defaults = {
include_answer = "basic",
},
---@type WebSearchEngineProviderResponseBodyFormatter
format_response_body = function(body) return body.anwser, nil end,
format_response_body = function(body) return body.answer, nil end,
},
serpapi = {
api_key_name = "SERPAPI_API_KEY",
@ -200,6 +200,7 @@ M._defaults = {
temperature = 0,
max_tokens = 8000,
},
---@type AvanteSupportedProvider
["claude-opus"] = {
__inherited_from = "claude",
@ -313,8 +314,12 @@ M._defaults = {
files = {
add_current = "<leader>ac", -- Add current buffer to selected files
},
providers = {
show_provides = "<leader>ap", -- Show providers selector
},
},
windows = {
---@alias AvantePosition "right" | "left" | "top" | "bottom" | "smart"
position = "right",
wrap = true, -- similar to vim.o.wrap

View File

@ -68,6 +68,11 @@ H.keymaps = function()
vim.keymap.set("n", "<Plug>(AvanteToggleHint)", function() M.toggle.hint() end)
vim.keymap.set("n", "<Plug>(AvanteToggleSuggestion)", function() M.toggle.suggestion() end)
vim.keymap.set("n", "<Plug>(AvanteShowProviders)", function()
local sidebar = M.get()
if sidebar then sidebar:show_providers_selector() end
end, { noremap = true, silent = true })
vim.keymap.set({ "n", "v" }, "<Plug>(AvanteConflictOurs)", function() Diff.choose("ours") end)
vim.keymap.set({ "n", "v" }, "<Plug>(AvanteConflictBoth)", function() Diff.choose("both") end)
vim.keymap.set({ "n", "v" }, "<Plug>(AvanteConflictTheirs)", function() Diff.choose("theirs") end)
@ -121,6 +126,14 @@ H.keymaps = function()
function() M.toggle.suggestion() end,
{ desc = "avante: toggle suggestion" }
)
Utils.safe_keymap_set("n", Config.mappings.show_providers, function()
local sidebar = M.get()
if sidebar then sidebar:show_providers_selector() end
end, {
desc = "avante: show providers selector",
noremap = true,
silent = true,
})
Utils.safe_keymap_set("n", Config.mappings.toggle.repomap, function() require("avante.repo_map").show() end, {
desc = "avante: display repo map",
noremap = true,

View File

@ -64,6 +64,7 @@ local DressingState = { winid = nil, input_winid = nil, input_bufnr = nil }
---@field __inherited_from? string
---@field temperature? number
---@field max_tokens? number
---@field reasoning_effort? string
---
---@class AvanteLLMUsage
---@field input_tokens number
@ -136,6 +137,7 @@ local DressingState = { winid = nil, input_winid = nil, input_bufnr = nil }
---@field gemini AvanteProviderFunctor
---@field cohere AvanteProviderFunctor
---@field bedrock AvanteBedrockProviderFunctor
local M = {}
---@class EnvironmentHandler

View File

@ -196,10 +196,6 @@ M.parse_messages = function(opts)
end
M.parse_response = function(ctx, data_stream, _, opts)
if data_stream:match('"%[DONE%]":') then
opts.on_stop({ reason = "complete" })
return
end
if data_stream:match('"delta":') then
---@type OpenAIChatResponse
local jsn = vim.json.decode(data_stream)
@ -227,7 +223,7 @@ M.parse_response = function(ctx, data_stream, _, opts)
end
ctx.last_think_content = choice.delta.reasoning
opts.on_chunk(choice.delta.reasoning)
elseif choice.delta.tool_calls then
elseif choice.delta.tool_calls and choice.delta.tool_calls ~= vim.NIL then
local tool_call = choice.delta.tool_calls[1]
if not ctx.tool_use_list then ctx.tool_use_list = {} end
if not ctx.tool_use_list[tool_call.index + 1] then
@ -274,6 +270,7 @@ M.parse_response_without_stream = function(data, _, opts)
end
end
local Log = require("avante.utils.log")
M.parse_curl_args = function(provider, prompt_opts)
local provider_conf, request_body = P.parse_config(provider)
local disable_tools = provider_conf.disable_tools or false
@ -282,7 +279,20 @@ M.parse_curl_args = function(provider, prompt_opts)
["Content-Type"] = "application/json",
}
<<<<<<< HEAD
-- Add appid header for baidu provider
if Config.provider == "baidu" then
local baidu_config = Config.get_provider("baidu")
if not baidu_config.appid or baidu_config.appid == "" then
error("Baidu provider requires 'appid' to be set in config")
end
headers["appid"] = baidu_config.appid
end
if P.env.require_api_key(base) then
=======
if P.env.require_api_key(provider_conf) then
>>>>>>> b6ae4dfe7fe443362f5f31d71797173ec12c2598
local api_key = provider.parse_api_key()
if api_key == nil then
error(Config.provider .. " API key is not set, please set it in your environment variable or config file")
@ -327,6 +337,8 @@ M.parse_curl_args = function(provider, prompt_opts)
tools = tools,
}, request_body),
}
-- 记录请求详细信息
Log.log_request(request.url, request.headers, request.body)
return request
end
return M

View File

@ -1081,6 +1081,76 @@ function Sidebar:on_mount(opts)
})
end
-- Add keymap to add current buffer while sidebar is open
if Config.mappings.providers and Config.mappings.providers.show_providers then
vim.keymap.set("n", Config.mappings.providers.show_providers, function()
local providers = require("avante.providers")
local current_provider = Config.provider
-- Create a new buffer
local bufnr = api.nvim_create_buf(false, true)
-- Set buffer content
local lines = {}
for provider, _ in pairs(providers) do
if provider == current_provider then
table.insert(lines, "> " .. provider .. " <")
else
table.insert(lines, " " .. provider)
end
end
api.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
-- Create a floating window
local width = 40
local height = #lines
local win_opts = {
relative = "editor",
width = width,
height = height,
col = (vim.o.columns - width) / 2,
row = (vim.o.lines - height) / 2 - 1,
style = "minimal",
border = "rounded",
}
local winid = api.nvim_open_win(bufnr, true, win_opts)
-- Highlight current provider
api.nvim_buf_add_highlight(bufnr, -1, "AvanteProviderCurrent", 0, 0, -1)
-- Key mappings
local function move_selection(direction)
local cursor = api.nvim_win_get_cursor(winid)
local line = cursor[1]
if direction == "up" and line > 1 then
api.nvim_win_set_cursor(winid, { line - 1, 0 })
elseif direction == "down" and line < #lines then
api.nvim_win_set_cursor(winid, { line + 1, 0 })
end
end
local function select_provider()
local cursor = api.nvim_win_get_cursor(winid)
local line = cursor[1]
local selected_provider = lines[line]:match("%S+$")
if selected_provider and selected_provider ~= current_provider then providers.refresh(selected_provider) end
api.nvim_win_close(winid, true)
end
vim.keymap.set("n", "<Up>", function() move_selection("up") end, { buffer = bufnr })
vim.keymap.set("n", "<Down>", function() move_selection("down") end, { buffer = bufnr })
vim.keymap.set("n", "<CR>", select_provider, { buffer = bufnr })
vim.keymap.set("n", "q", function() api.nvim_win_close(winid, true) end, { buffer = bufnr })
end, {
desc = "avante: show providers selector",
noremap = true,
silent = true,
})
end
api.nvim_set_option_value("wrap", Config.windows.wrap, { win = self.result_container.winid })
local current_apply_extmark_id = nil
@ -1283,6 +1353,12 @@ end
--- Initialize the sidebar instance.
--- @return avante.Sidebar The Sidebar instance.
function Sidebar:initialize()
-- Add keymap to show providers selector
vim.keymap.set("n", "<leader>ap", function() self:show_providers_selector() end, { noremap = true, silent = true })
self.code.winid = api.nvim_get_current_win()
self.code.bufnr = api.nvim_get_current_buf()
self.code.selection = Utils.get_visual_selection_and_range()
self.code.winid = api.nvim_get_current_win()
self.code.bufnr = api.nvim_get_current_buf()
self.code.selection = Utils.get_visual_selection_and_range()
@ -2339,6 +2415,70 @@ function Sidebar:render(opts)
return self
end
function Sidebar:show_providers_selector()
local providers = require("avante.providers")
local current_provider = Config.provider
-- Create a new buffer
local bufnr = api.nvim_create_buf(false, true)
-- Set buffer content
local lines = {}
for provider, _ in pairs(providers) do
if provider == current_provider then
table.insert(lines, "> " .. provider .. " <")
else
table.insert(lines, " " .. provider)
end
end
api.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
-- Create a floating window
local width = 40
local height = #lines
local win_opts = {
relative = "editor",
width = width,
height = height,
col = (vim.o.columns - width) / 2,
row = (vim.o.lines - height) / 2 - 1,
style = "minimal",
border = "rounded",
}
local winid = api.nvim_open_win(bufnr, true, win_opts)
-- Highlight current provider
api.nvim_buf_add_highlight(bufnr, -1, "AvanteProviderCurrent", 0, 0, -1)
-- Key mappings
local function move_selection(direction)
local cursor = api.nvim_win_get_cursor(winid)
local line = cursor[1]
if direction == "up" and line > 1 then
api.nvim_win_set_cursor(winid, { line - 1, 0 })
elseif direction == "down" and line < #lines then
api.nvim_win_set_cursor(winid, { line + 1, 0 })
end
end
local function select_provider()
local cursor = api.nvim_win_get_cursor(winid)
local line = cursor[1]
local selected_provider = lines[line]:match("%S+$")
if selected_provider and selected_provider ~= current_provider then providers.refresh(selected_provider) end
api.nvim_win_close(winid, true)
end
vim.keymap.set("n", "<Up>", function() move_selection("up") end, { buffer = bufnr })
vim.keymap.set("n", "<Down>", function() move_selection("down") end, { buffer = bufnr })
vim.keymap.set("n", "<CR>", select_provider, { buffer = bufnr })
vim.keymap.set("n", "q", function() api.nvim_win_close(winid, true) end, { buffer = bufnr })
end
function Sidebar:create_selected_files_container()
if self.selected_files_container then self.selected_files_container:unmount() end

View File

@ -665,6 +665,19 @@ function M.scan_directory_respect_gitignore(options)
local directory = options.directory
local gitignore_path = directory .. "/.gitignore"
local gitignore_patterns, gitignore_negate_patterns = M.parse_gitignore(gitignore_path)
-- Convert relative paths in gitignore to absolute paths based on project root
local project_root = M.get_project_root()
local function to_absolute_path(pattern)
-- Skip if already absolute path
if pattern:sub(1, 1) == "/" then return pattern end
-- Convert relative path to absolute
return Path:new(project_root, pattern):absolute()
end
gitignore_patterns = vim.tbl_map(to_absolute_path, gitignore_patterns)
gitignore_negate_patterns = vim.tbl_map(to_absolute_path, gitignore_negate_patterns)
return M.scan_directory({
directory = directory,
gitignore_patterns = gitignore_patterns,

31
lua/avante/utils/log.lua Normal file
View File

@ -0,0 +1,31 @@
local M = {}
--
-- local log_file = vim.fn.stdpath("cache") .. "/avante_requests.log"
local log_file = "/tmp/avante/avante_requests.log"
function M.log_request(url, headers, body)
local timestamp = os.date("%Y-%m-%d %H:%M:%S")
local log_entry = string.format(
[[
[%s] Request Details:
URL: %s
Headers:
%s
Body:
%s
]],
timestamp,
url,
vim.inspect(headers),
vim.inspect(body)
)
-- Append to log file
local file = io.open(log_file, "a")
if file then
file:write(log_entry .. "\n\n")
file:close()
end
end
return M

22
note.txt Normal file
View File

@ -0,0 +1,22 @@
Failed to run `config` for avante.nvim
...share/nvim/lazy/lazy.nvim/lua/lazy/core/handler/keys.lua:35: attempt to index local 'ret' (a nil value)
# stacktrace:
- /lazy.nvim/lua/lazy/core/util.lua:123 _in_ **__index**
- /lazy.nvim/lua/lazy/core/handler/keys.lua:35 _in_ **parse**
- /lazy.nvim/lua/lazy/core/handler/keys.lua:63 _in_ **have**
- /avante.nvim/lua/avante/utils/init.lua:163 _in_ **func**
- vim/shared.lua:274 _in_ **tbl_filter**
- /avante.nvim/lua/avante/utils/init.lua:163 _in_ **safe_keymap_set**
- /avante.nvim/lua/avante/init.lua:129 _in_ **keymaps**
- /avante.nvim/lua/avante/init.lua:386 _in_ **setup**
- /lazy.nvim/lua/lazy/core/loader.lua:387
- /lazy.nvim/lua/lazy/core/util.lua:135 _in_ **try**
- /lazy.nvim/lua/lazy/core/loader.lua:395 _in_ **config**
- /lazy.nvim/lua/lazy/core/loader.lua:362 _in_ **_load**
- /lazy.nvim/lua/lazy/core/loader.lua:197 _in_ **load**
- /lazy.nvim/lua/lazy/core/loader.lua:127 _in_ **startup**
- /lazy.nvim/lua/lazy/init.lua:112 _in_ **setup**
- ~/.config/nvim/lua/config/lazy.lua:17
- ~/.config/nvim/init.lua:2

69
tree.txt Normal file
View File

@ -0,0 +1,69 @@
.
├── autoload
│   └── avante.vim
├── Build.ps1
├── build.sh
├─ ─ Cargo.lock
├── Cargo.toml
├── crates
│   ├── avante-html2md
│   │   ├── Cargo.toml
│   │   └── src
│   ├── avante-repo-map
│   │   ├── Cargo.toml
│   │   ├── queries
│   │   └── src
│   ├── avante-templates
│   │   ├── Cargo.toml
│   │   └── src
│   └── avante-tokenizers
│   ├── Cargo.lock
│   ├── Cargo.toml
│   ├── README.md
│   └── src
├── LICENSE
├── lua
│   ├── avante
│   │   ├── api.lua
│   │   ├── clipboard.lua
│   │   ├── config.lua
│   │   ├── diff.lua
│   │   ├── file_selector.lua
│   │   ├── health.lua
│   │   ├── highlights.lua
│   │   ├── html2md.lua
│   │   ├── init.lua
│   │   ├── llm.lua
│   │   ├── llm_tools.lua
│   │   ├── path.lua
│   │   ├── prompt_input.lua
│   │   ├── providers
│   │   ├── range.lua
│   │   ├── repo_map.lua
│   │   ├── selection.lua
│   │   ├── selection_result.lua
│   │   ├── sidebar.lua
│   │   ├── suggestion.lua
│   │   ├── templates
│   │   ├── tokenizers.lua
│   │   ├── types.lua
│   │   └── utils
│   ├── avante_lib.lua
│   └── cmp_avante
│   ├── commands.lua
│   └── mentions.lua
├── Makefile
├── plugin
│   └── avante.lua
├── README.md
├── stylua.toml
├── syntax
│   └── jinja.vim
├── tests
│   ├── llm_tools_spec.lua
│   └── utils
│   ├── file_spec.lua
│   └── init_spec.lua
└── tree.txt
21 directories, 45 files