fix: prompts (#1715)

This commit is contained in:
yetone
2025-03-25 23:16:03 +08:00
committed by GitHub
parent a2aec079c9
commit d82eb8534e
4 changed files with 40 additions and 14 deletions

View File

@@ -62,15 +62,13 @@ end
---@param history avante.ChatHistory
---@param cb fun(memory: avante.ChatMemory | nil): nil
function M.summarize_memory(bufnr, history, cb)
local system_prompt =
[[Summarize the following conversation to extract the most critical information (such as languages used, conversation style, tech stack, considerations, user information, etc.) for memory in subsequent conversations. Since it is for memory purposes, be detailed and rigorous to ensure that no information from previous summaries is lost in the newly generated summary.]]
local system_prompt = [[You are a helpful AI assistant tasked with summarizing conversations.]]
local entries = Utils.history.filter_active_entries(history.entries)
if #entries == 0 then
cb(nil)
return
end
if history.memory then
system_prompt = system_prompt .. "\n\nThe previous summary is:\n\n" .. history.memory.content
entries = vim
.iter(entries)
:filter(function(entry) return entry.timestamp > history.memory.last_summarized_timestamp end)
@@ -87,15 +85,20 @@ function M.summarize_memory(bufnr, history, cb)
return
end
Utils.debug("summarize memory", #history_messages, history_messages[#history_messages].content)
local user_prompt =
[[Provide a detailed but concise summary of our conversation above. Focus on information that would be helpful for continuing the conversation, including what we did, what we're doing, which files we're working on, and what we're going to do next.]]
if history.memory then user_prompt = user_prompt .. "\n\nThe previous summary is:\n\n" .. history.memory.content end
table.insert(history_messages, {
role = "user",
content = user_prompt,
})
local response_content = ""
local provider = Providers[Config.memory_summary_provider or Config.provider]
M.curl({
provider = provider,
prompt_opts = {
system_prompt = system_prompt,
messages = {
{ role = "user", content = vim.json.encode(history_messages) },
},
messages = history_messages,
},
handler_opts = {
on_start = function(_) end,

View File

@@ -10,13 +10,33 @@ local M = setmetatable({}, Base)
M.name = "bash"
local banned_commands = {
"alias",
"curl",
"curlie",
"wget",
"axel",
"aria2c",
"nc",
"telnet",
"lynx",
"w3m",
"links",
"httpie",
"xh",
"http-prompt",
"chrome",
"firefox",
"safari",
}
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. Do not use bash command to read or modify files, or you will be fired!]]
end
return [[Executes a given bash command in a persistent shell session with optional timeout, ensuring proper handling and security measures.
local res = ([[Executes a given bash command in a persistent shell session with optional timeout, ensuring proper handling and security measures.
Do not use bash command to read or modify files, or you will be fired!
@@ -28,7 +48,7 @@ Before executing the command, please follow these steps:
2. Security Check:
- For security and to limit the threat of a prompt injection attack, some commands are limited or banned. If you use a disallowed command, you will receive an error message explaining the restriction. Explain the error to the User.
- Verify that the command is not one of the banned commands: ${BANNED_COMMANDS.join(', ')}.
- Verify that the command is not one of the banned commands: ${BANNED_COMMANDS}.
3. Command Execution:
- After ensuring proper quoting, execute the command.
@@ -155,14 +175,15 @@ gh pr create --title "the pr title" --body "$(cat <<'EOF'
## Test plan
[Checklist of TODOs for testing the pull request...]
🤖 Generated with ${process.env.USER_TYPE === 'ant' ? `[${PRODUCT_NAME}](${PRODUCT_URL})` : PRODUCT_NAME}
🤖 Generated with [avante.nvim](https://github.com/yetone/avante.nvim)
EOF
)"
</example>
Important:
- Return an empty response - the user will see the gh output directly
- Never update git config]]
- Never update git config]]):gsub("${BANNED_COMMANDS}", table.concat(banned_commands, ", "))
return res
end
---@type AvanteLLMToolParam

View File

@@ -16,10 +16,11 @@ M.description =
- If you are searching for a specific class definition like "class Foo", use the `glob` tool instead, to find the match more quickly
Usage notes:
1. Launch multiple agents concurrently whenever possible, to maximize performance
2. When the agent is done, it will return a single message back to you
3. Each agent invocation is stateless
4. The agent's outputs should generally be trusted]]
1. Launch multiple agents concurrently whenever possible, to maximize performance; to do that, use a single message with multiple tool uses
2. When the agent is done, it will return a single message back to you. The result returned by the agent is not visible to the user. To show the user the result, you should send a text message back to the user with a concise summary of the result.
3. Each agent invocation is stateless. You will not be able to send additional messages to the agent, nor will the agent be able to communicate with you outside of its final report. Therefore, your prompt should contain a highly detailed task description for the agent to perform autonomously and you should specify exactly what information the agent should return back to you in its final and only message to you.
4. The agent's outputs should generally be trusted
5. IMPORTANT: The agent can not use `bash`, `write`, `str_replace`, so can not modify files. If you want to use these tools, use them directly instead of going through the agent.]]
---@type AvanteLLMToolParam
M.param = {

View File

@@ -2314,6 +2314,7 @@ function Sidebar:add_chat_history(message, options)
Path.history.save(self.code.bufnr, self.chat_history)
if self.chat_history.title == "untitled" then
Llm.summarize_chat_thread_title(message.content, function(title)
self:reload_chat_history()
if title then self.chat_history.title = title end
Path.history.save(self.code.bufnr, self.chat_history)
end)