fix: copilot's openai tool description cannot use long text (#1700)

This commit is contained in:
yetone
2025-03-24 19:54:06 +08:00
committed by GitHub
parent e20a3ff111
commit 25e9b1c111
5 changed files with 18 additions and 8 deletions

View File

@@ -2,14 +2,21 @@ local Path = require("plenary.path")
local Utils = require("avante.utils")
local Helpers = require("avante.llm_tools.helpers")
local Base = require("avante.llm_tools.base")
local Config = require("avante.config")
local Providers = require("avante.providers")
---@class AvanteLLMTool
local M = setmetatable({}, Base)
M.name = "bash"
M.description =
[[Executes a given bash command in a persistent shell session with optional timeout, ensuring proper handling and security measures.
M.get_description = function()
local provider = Providers[Config.provider]
if Config.provider:match("copilot") and provider.model and provider.model:match("gpt") then
return [[Executes a given bash command in a persistent shell session with optional timeout, ensuring proper handling and security measures.]]
end
return [[Executes a given bash command in a persistent shell session with optional timeout, ensuring proper handling and security measures.
Before executing the command, please follow these steps:
@@ -154,6 +161,7 @@ EOF
Important:
- Return an empty response - the user will see the gh output directly
- Never update git config]]
end
---@type AvanteLLMToolParam
M.param = {

View File

@@ -37,7 +37,7 @@ function M:transform_tool(tool)
local input_schema_properties, required = Utils.llm_tool_param_fields_to_json_schema(tool.param.fields)
return {
name = tool.name,
description = tool.description,
description = tool.get_description and tool.get_description() or tool.description,
input_schema = {
type = "object",
properties = input_schema_properties,

View File

@@ -34,7 +34,7 @@ function M:transform_tool(tool)
type = "function",
["function"] = {
name = tool.name,
description = tool.description,
description = tool.get_description and tool.get_description() or tool.description,
parameters = parameters,
},
}

View File

@@ -345,7 +345,8 @@ vim.g.avante_login = vim.g.avante_login
---
---@class AvanteLLMTool
---@field name string
---@field description string
---@field description? string
---@field get_description? fun(): string
---@field func? AvanteLLMToolFunc
---@field param AvanteLLMToolParam
---@field returns AvanteLLMToolReturn[]
@@ -360,7 +361,8 @@ vim.g.avante_login = vim.g.avante_login
---@class AvanteLLMToolParamField
---@field name string
---@field description string
---@field description? string
---@field get_description? fun(): string
---@field type 'string' | 'integer' | 'boolean' | 'object'
---@field fields? AvanteLLMToolParamField[]
---@field optional? boolean

View File

@@ -1208,14 +1208,14 @@ function M.llm_tool_param_fields_to_json_schema(fields)
local properties_, required_ = M.llm_tool_param_fields_to_json_schema(field.fields)
properties[field.name] = {
type = field.type,
description = field.description,
description = field.get_description and field.get_description() or field.description,
properties = properties_,
required = required_,
}
else
properties[field.name] = {
type = field.type,
description = field.description,
description = field.get_description and field.get_description() or field.description,
}
end
if not field.optional then table.insert(required, field.name) end