fix: the foolish copilot/claude-3.7-sonnet is unable to invoke the attempt_completion tool as instructed (#2095)
This commit is contained in:
@@ -220,7 +220,7 @@ M._defaults = {
|
||||
endpoint = "https://api.openai.com/v1",
|
||||
model = "gpt-4o",
|
||||
timeout = 30000, -- Timeout in milliseconds, increase this for reasoning models
|
||||
temperature = 0,
|
||||
temperature = 0.75,
|
||||
max_completion_tokens = 16384, -- Increase this to include reasoning tokens (for reasoning models)
|
||||
reasoning_effort = "medium", -- low|medium|high, only used for reasoning models
|
||||
},
|
||||
@@ -231,7 +231,7 @@ M._defaults = {
|
||||
proxy = nil, -- [protocol://]host[:port] Use this proxy
|
||||
allow_insecure = false, -- Allow insecure server connections
|
||||
timeout = 30000, -- Timeout in milliseconds
|
||||
temperature = 0,
|
||||
temperature = 0.75,
|
||||
max_tokens = 20480,
|
||||
},
|
||||
---@type AvanteAzureProvider
|
||||
@@ -240,7 +240,7 @@ M._defaults = {
|
||||
deployment = "", -- Azure deployment name (e.g., "gpt-4o", "my-gpt-4o-deployment")
|
||||
api_version = "2024-12-01-preview",
|
||||
timeout = 30000, -- Timeout in milliseconds, increase this for reasoning models
|
||||
temperature = 0,
|
||||
temperature = 0.75,
|
||||
max_completion_tokens = 20480, -- Increase this to include reasoning tokens (for reasoning models)
|
||||
reasoning_effort = "medium", -- low|medium|high, only used for reasoning models
|
||||
},
|
||||
@@ -249,14 +249,14 @@ M._defaults = {
|
||||
endpoint = "https://api.anthropic.com",
|
||||
model = "claude-3-7-sonnet-20250219",
|
||||
timeout = 30000, -- Timeout in milliseconds
|
||||
temperature = 0,
|
||||
temperature = 0.75,
|
||||
max_tokens = 20480,
|
||||
},
|
||||
---@type AvanteSupportedProvider
|
||||
bedrock = {
|
||||
model = "anthropic.claude-3-5-sonnet-20241022-v2:0",
|
||||
timeout = 30000, -- Timeout in milliseconds
|
||||
temperature = 0,
|
||||
temperature = 0.75,
|
||||
max_tokens = 20480,
|
||||
aws_region = "", -- AWS region to use for authentication and bedrock API
|
||||
aws_profile = "", -- AWS profile to use for authentication, if unspecified uses default credentials chain
|
||||
@@ -266,7 +266,7 @@ M._defaults = {
|
||||
endpoint = "https://generativelanguage.googleapis.com/v1beta/models",
|
||||
model = "gemini-2.0-flash",
|
||||
timeout = 30000, -- Timeout in milliseconds
|
||||
temperature = 0,
|
||||
temperature = 0.75,
|
||||
max_tokens = 8192,
|
||||
},
|
||||
---@type AvanteSupportedProvider
|
||||
@@ -274,7 +274,7 @@ M._defaults = {
|
||||
endpoint = "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models",
|
||||
model = "gemini-1.5-flash-002",
|
||||
timeout = 30000, -- Timeout in milliseconds
|
||||
temperature = 0,
|
||||
temperature = 0.75,
|
||||
max_tokens = 20480,
|
||||
},
|
||||
---@type AvanteSupportedProvider
|
||||
@@ -282,7 +282,7 @@ M._defaults = {
|
||||
endpoint = "https://api.cohere.com/v2",
|
||||
model = "command-r-plus-08-2024",
|
||||
timeout = 30000, -- Timeout in milliseconds
|
||||
temperature = 0,
|
||||
temperature = 0.75,
|
||||
max_tokens = 20480,
|
||||
},
|
||||
---@type AvanteSupportedProvider
|
||||
@@ -290,7 +290,7 @@ M._defaults = {
|
||||
endpoint = "http://127.0.0.1:11434",
|
||||
timeout = 30000, -- Timeout in milliseconds
|
||||
options = {
|
||||
temperature = 0,
|
||||
temperature = 0.75,
|
||||
num_ctx = 20480,
|
||||
keep_alive = "5m",
|
||||
},
|
||||
@@ -300,7 +300,7 @@ M._defaults = {
|
||||
endpoint = "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/antrhopic/models",
|
||||
model = "claude-3-5-sonnet-v2@20241022",
|
||||
timeout = 30000, -- Timeout in milliseconds
|
||||
temperature = 0,
|
||||
temperature = 0.75,
|
||||
max_tokens = 20480,
|
||||
},
|
||||
---To add support for custom provider, follow the format below
|
||||
@@ -312,7 +312,7 @@ M._defaults = {
|
||||
__inherited_from = "claude",
|
||||
model = "claude-3-5-haiku-20241022",
|
||||
timeout = 30000, -- Timeout in milliseconds
|
||||
temperature = 0,
|
||||
temperature = 0.75,
|
||||
max_tokens = 8192,
|
||||
},
|
||||
---@type AvanteSupportedProvider
|
||||
@@ -320,7 +320,7 @@ M._defaults = {
|
||||
__inherited_from = "claude",
|
||||
model = "claude-3-opus-20240229",
|
||||
timeout = 30000, -- Timeout in milliseconds
|
||||
temperature = 0,
|
||||
temperature = 0.75,
|
||||
max_tokens = 20480,
|
||||
},
|
||||
["openai-gpt-4o-mini"] = {
|
||||
|
||||
@@ -805,6 +805,11 @@ function M._stream(opts)
|
||||
})
|
||||
end
|
||||
opts.on_messages_add(messages)
|
||||
local the_last_tool_use = tool_use_list[#tool_use_list]
|
||||
if the_last_tool_use and the_last_tool_use.name == "attempt_completion" then
|
||||
opts.on_stop({ reason = "complete" })
|
||||
return
|
||||
end
|
||||
local new_opts = vim.tbl_deep_extend("force", opts, {
|
||||
history_messages = opts.get_history_messages(),
|
||||
})
|
||||
@@ -908,7 +913,9 @@ function M._stream(opts)
|
||||
if message then break end
|
||||
::continue::
|
||||
end
|
||||
if not completed_attempt_completion_tool_use and opts.on_messages_add then
|
||||
local user_reminder_count = opts.session_ctx.user_reminder_count or 0
|
||||
if not completed_attempt_completion_tool_use and opts.on_messages_add and user_reminder_count < 3 then
|
||||
opts.session_ctx.user_reminder_count = user_reminder_count + 1
|
||||
local message = HistoryMessage:new({
|
||||
role = "user",
|
||||
content = "<user-reminder>You should use tool calls to answer the question, for example, use attempt_completion if the job is done.</user-reminder>",
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user