fix: the foolish copilot/claude-3.7-sonnet is unable to invoke the attempt_completion tool as instructed (#2095)

This commit is contained in:
yetone
2025-05-29 03:18:15 +08:00
committed by GitHub
parent 697384f1cb
commit 7fd6cf3d64
5 changed files with 50 additions and 27 deletions

View File

@@ -1,6 +1,6 @@
local Base = require("avante.llm_tools.base")
local Config = require("avante.config")
-- local HistoryMessage = require("avante.history_message")
local HistoryMessage = require("avante.history_message")
---@alias AttemptCompletionInput {result: string, command?: string}
@@ -58,13 +58,13 @@ function M.func(opts, on_log, on_complete, session_ctx)
local sidebar = require("avante").get()
if not sidebar then return false, "Avante sidebar not found" end
session_ctx.attempt_completion_is_called = true
-- local message = HistoryMessage:new({
-- role = "assistant",
-- content = opts.result,
-- }, {
-- just_for_display = true,
-- })
-- sidebar:add_history_messages({ message })
local message = HistoryMessage:new({
role = "assistant",
content = opts.result,
}, {
just_for_display = true,
})
sidebar:add_history_messages({ message })
if opts.command then
require("avante.llm_tools.bash").func({ command = opts.command }, on_log, on_complete, session_ctx)
else

View File

@@ -41,13 +41,29 @@ M.returns = {
}
---@type AvanteLLMToolFunc<{ rel_path: string, pattern: string }>
function M.func(opts, on_log)
function M.func(opts, on_log, on_complete, session_ctx)
local abs_path = Helpers.get_abs_path(opts.rel_path)
if not Helpers.has_permission_to_access(abs_path) then return "", "No permission to access path: " .. abs_path end
if on_log then on_log("path: " .. abs_path) end
if on_log then on_log("pattern: " .. opts.pattern) end
local files = vim.fn.glob(abs_path .. "/" .. opts.pattern, true, true)
return vim.json.encode(files), nil
local truncated_files = {}
local is_truncated = false
local size = 0
for _, file in ipairs(files) do
size = size + #file
if size > 1024 * 10 then
is_truncated = true
break
end
table.insert(truncated_files, file)
end
local result = vim.json.encode({
matches = truncated_files,
is_truncated = is_truncated,
})
if not on_complete then return result, nil end
on_complete(result, nil)
end
return M