refactor: remove use_xml_format (#1535)
This commit is contained in:
@@ -15,6 +15,13 @@ impl State<'_> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
struct SelectedCode {
|
||||||
|
path: String,
|
||||||
|
content: Option<String>,
|
||||||
|
file_type: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
struct SelectedFile {
|
struct SelectedFile {
|
||||||
path: String,
|
path: String,
|
||||||
@@ -24,11 +31,12 @@ struct SelectedFile {
|
|||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
struct TemplateContext {
|
struct TemplateContext {
|
||||||
use_xml_format: bool,
|
|
||||||
ask: bool,
|
ask: bool,
|
||||||
code_lang: String,
|
code_lang: String,
|
||||||
selected_files: Option<Vec<SelectedFile>>,
|
selected_files: Option<Vec<SelectedFile>>,
|
||||||
selected_code: Option<String>,
|
selected_code: Option<SelectedCode>,
|
||||||
|
recently_viewed_files: Option<Vec<String>>,
|
||||||
|
relevant_files: Option<Vec<String>>,
|
||||||
project_context: Option<String>,
|
project_context: Option<String>,
|
||||||
diagnostics: Option<String>,
|
diagnostics: Option<String>,
|
||||||
system_info: Option<String>,
|
system_info: Option<String>,
|
||||||
@@ -50,11 +58,12 @@ fn render(state: &State, template: &str, context: TemplateContext) -> LuaResult<
|
|||||||
|
|
||||||
Ok(jinja_template
|
Ok(jinja_template
|
||||||
.render(context! {
|
.render(context! {
|
||||||
use_xml_format => context.use_xml_format,
|
|
||||||
ask => context.ask,
|
ask => context.ask,
|
||||||
code_lang => context.code_lang,
|
code_lang => context.code_lang,
|
||||||
selected_files => context.selected_files,
|
selected_files => context.selected_files,
|
||||||
selected_code => context.selected_code,
|
selected_code => context.selected_code,
|
||||||
|
recently_viewed_files => context.recently_viewed_files,
|
||||||
|
relevant_files => context.relevant_files,
|
||||||
project_context => context.project_context,
|
project_context => context.project_context,
|
||||||
diagnostics => context.diagnostics,
|
diagnostics => context.diagnostics,
|
||||||
system_info => context.system_info,
|
system_info => context.system_info,
|
||||||
|
|||||||
@@ -553,7 +553,6 @@ M.BASE_PROVIDER_KEYS = {
|
|||||||
"local",
|
"local",
|
||||||
"_shellenv",
|
"_shellenv",
|
||||||
"tokenizer_id",
|
"tokenizer_id",
|
||||||
"use_xml_format",
|
|
||||||
"role_map",
|
"role_map",
|
||||||
"support_prompt_caching",
|
"support_prompt_caching",
|
||||||
"__inherited_from",
|
"__inherited_from",
|
||||||
|
|||||||
@@ -114,7 +114,6 @@ function M.generate_prompts(opts)
|
|||||||
local system_info = Utils.get_system_info()
|
local system_info = Utils.get_system_info()
|
||||||
|
|
||||||
local template_opts = {
|
local template_opts = {
|
||||||
use_xml_format = provider.use_xml_format,
|
|
||||||
ask = opts.ask, -- TODO: add mode without ask instruction
|
ask = opts.ask, -- TODO: add mode without ask instruction
|
||||||
code_lang = opts.code_lang,
|
code_lang = opts.code_lang,
|
||||||
selected_files = opts.selected_files,
|
selected_files = opts.selected_files,
|
||||||
@@ -156,11 +155,7 @@ function M.generate_prompts(opts)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if instructions then
|
if instructions then
|
||||||
if opts.use_xml_format then
|
table.insert(messages, { role = "user", content = string.format("<question>%s</question>", instructions) })
|
||||||
table.insert(messages, { role = "user", content = string.format("<question>%s</question>", instructions) })
|
|
||||||
else
|
|
||||||
table.insert(messages, { role = "user", content = string.format("QUESTION:\n%s", instructions) })
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local remaining_tokens = max_tokens - Utils.tokens.calculate_tokens(system_prompt)
|
local remaining_tokens = max_tokens - Utils.tokens.calculate_tokens(system_prompt)
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ local P = require("avante.providers")
|
|||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
M.api_key_name = "BEDROCK_KEYS"
|
M.api_key_name = "BEDROCK_KEYS"
|
||||||
M.use_xml_format = true
|
|
||||||
|
|
||||||
M = setmetatable(M, {
|
M = setmetatable(M, {
|
||||||
__index = function(_, k)
|
__index = function(_, k)
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ end
|
|||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
M.api_key_name = "ANTHROPIC_API_KEY"
|
M.api_key_name = "ANTHROPIC_API_KEY"
|
||||||
M.use_xml_format = true
|
|
||||||
M.support_prompt_caching = true
|
M.support_prompt_caching = true
|
||||||
|
|
||||||
M.role_map = {
|
M.role_map = {
|
||||||
|
|||||||
@@ -224,8 +224,6 @@ M = setmetatable(M, {
|
|||||||
-- default to gpt-4o as tokenizer
|
-- default to gpt-4o as tokenizer
|
||||||
if t[k].tokenizer_id == nil then t[k].tokenizer_id = "gpt-4o" end
|
if t[k].tokenizer_id == nil then t[k].tokenizer_id = "gpt-4o" end
|
||||||
|
|
||||||
if t[k].use_xml_format == nil then t[k].use_xml_format = true end
|
|
||||||
|
|
||||||
if t[k].is_env_set == nil then t[k].is_env_set = function() return E.parse_envvar(t[k]) ~= nil end end
|
if t[k].is_env_set == nil then t[k].is_env_set = function() return E.parse_envvar(t[k]) ~= nil end end
|
||||||
|
|
||||||
if t[k].setup == nil then
|
if t[k].setup == nil then
|
||||||
|
|||||||
@@ -220,13 +220,24 @@ function Selection:create_editing_input()
|
|||||||
|
|
||||||
local diagnostics = Utils.get_current_selection_diagnostics(code_bufnr, self.selection)
|
local diagnostics = Utils.get_current_selection_diagnostics(code_bufnr, self.selection)
|
||||||
|
|
||||||
|
---@type AvanteSelectedCode | nil
|
||||||
|
local selected_code = nil
|
||||||
|
|
||||||
|
if self.selection then
|
||||||
|
selected_code = {
|
||||||
|
content = self.selection.content,
|
||||||
|
file_type = self.selection.filetype,
|
||||||
|
path = self.selection.filepath,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
Llm.stream({
|
Llm.stream({
|
||||||
ask = true,
|
ask = true,
|
||||||
project_context = vim.json.encode(project_context),
|
project_context = vim.json.encode(project_context),
|
||||||
diagnostics = vim.json.encode(diagnostics),
|
diagnostics = vim.json.encode(diagnostics),
|
||||||
selected_files = { { content = code_content, file_type = filetype, path = "" } },
|
selected_files = { { content = code_content, file_type = filetype, path = "" } },
|
||||||
code_lang = filetype,
|
code_lang = filetype,
|
||||||
selected_code = self.selection.content,
|
selected_code = selected_code,
|
||||||
instructions = input,
|
instructions = input,
|
||||||
mode = "editing",
|
mode = "editing",
|
||||||
on_start = on_start,
|
on_start = on_start,
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
---@class avante.SelectionResult
|
---@class avante.SelectionResult
|
||||||
|
---@field filepath string Filepath of the selected content
|
||||||
|
---@field filetype string Filetype of the selected content
|
||||||
---@field content string Selected content
|
---@field content string Selected content
|
||||||
---@field range avante.Range Selection range
|
---@field range avante.Range Selection range
|
||||||
local SelectionResult = {}
|
local SelectionResult = {}
|
||||||
@@ -7,8 +9,10 @@ SelectionResult.__index = SelectionResult
|
|||||||
-- Create a selection content and range
|
-- Create a selection content and range
|
||||||
---@param content string Selected content
|
---@param content string Selected content
|
||||||
---@param range avante.Range Selection range
|
---@param range avante.Range Selection range
|
||||||
function SelectionResult:new(content, range)
|
function SelectionResult:new(filepath, filetype, content, range)
|
||||||
local instance = setmetatable({}, SelectionResult)
|
local instance = setmetatable({}, self)
|
||||||
|
instance.filepath = filepath
|
||||||
|
instance.filetype = filetype
|
||||||
instance.content = content
|
instance.content = content
|
||||||
instance.range = range
|
instance.range = range
|
||||||
return instance
|
return instance
|
||||||
|
|||||||
@@ -166,7 +166,6 @@ end
|
|||||||
function Sidebar:focus_input()
|
function Sidebar:focus_input()
|
||||||
if self.input_container and self.input_container.winid and api.nvim_win_is_valid(self.input_container.winid) then
|
if self.input_container and self.input_container.winid and api.nvim_win_is_valid(self.input_container.winid) then
|
||||||
api.nvim_set_current_win(self.input_container.winid)
|
api.nvim_set_current_win(self.input_container.winid)
|
||||||
api.nvim_feedkeys("i", "n", false)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -2357,8 +2356,15 @@ function Sidebar:create_input_container(opts)
|
|||||||
local function get_generate_prompts_options(request, summarize_memory, cb)
|
local function get_generate_prompts_options(request, summarize_memory, cb)
|
||||||
local filetype = api.nvim_get_option_value("filetype", { buf = self.code.bufnr })
|
local filetype = api.nvim_get_option_value("filetype", { buf = self.code.bufnr })
|
||||||
|
|
||||||
local selected_code_content = nil
|
---@type AvanteSelectedCode | nil
|
||||||
if self.code.selection ~= nil then selected_code_content = self.code.selection.content end
|
local selected_code = nil
|
||||||
|
if self.code.selection ~= nil then
|
||||||
|
selected_code = {
|
||||||
|
path = self.code.selection.filepath,
|
||||||
|
file_type = self.code.selection.filetype,
|
||||||
|
content = self.code.selection.content,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
local mentions = Utils.extract_mentions(request)
|
local mentions = Utils.extract_mentions(request)
|
||||||
request = mentions.new_content
|
request = mentions.new_content
|
||||||
@@ -2397,7 +2403,7 @@ function Sidebar:create_input_container(opts)
|
|||||||
diagnostics = vim.json.encode(diagnostics),
|
diagnostics = vim.json.encode(diagnostics),
|
||||||
history_messages = history_messages,
|
history_messages = history_messages,
|
||||||
code_lang = filetype,
|
code_lang = filetype,
|
||||||
selected_code = selected_code_content,
|
selected_code = selected_code,
|
||||||
instructions = request,
|
instructions = request,
|
||||||
mode = Config.behaviour.enable_cursor_planning_mode and "cursor-planning" or "planning",
|
mode = Config.behaviour.enable_cursor_planning_mode and "cursor-planning" or "planning",
|
||||||
tools = tools,
|
tools = tools,
|
||||||
|
|||||||
@@ -1,54 +1,25 @@
|
|||||||
{%- if use_xml_format -%}
|
{% if selected_files -%}
|
||||||
|
<selected_files>
|
||||||
{% if selected_code -%}
|
{%- for file in selected_files %}
|
||||||
{% for file in selected_files %}
|
<file>
|
||||||
<filepath>{{file.path}}</filepath>
|
<filepath>{{file.path}}</filepath>
|
||||||
|
<content>
|
||||||
<context>
|
|
||||||
```{{file.file_type}}
|
```{{file.file_type}}
|
||||||
{{file.content}}
|
{{file.content}}
|
||||||
```
|
```
|
||||||
</context>
|
</content>
|
||||||
{% endfor %}
|
</file>
|
||||||
|
{%- endfor %}
|
||||||
<code>
|
</selected_files>
|
||||||
```{{code_lang}}
|
|
||||||
{{selected_code}}
|
|
||||||
```
|
|
||||||
</code>
|
|
||||||
{%- else -%}
|
|
||||||
{% for file in selected_files %}
|
|
||||||
<filepath>{{file.path}}</filepath>
|
|
||||||
|
|
||||||
<code>
|
|
||||||
```{{file.file_type}}
|
|
||||||
{{file.content}}
|
|
||||||
```
|
|
||||||
</code>
|
|
||||||
{% endfor %}
|
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
{% else %}
|
|
||||||
{% if selected_code -%}
|
{% if selected_code -%}
|
||||||
{% for file in selected_files %}
|
<selected_code>
|
||||||
FILEPATH: {{file.path}}
|
<filepath>{{selected_code.path}}</filepath>
|
||||||
|
<content>
|
||||||
CONTEXT:
|
```{{selected_code.file_type}}
|
||||||
```{{file.file_type}}
|
{{selected_code.content}}
|
||||||
{{file.content}}
|
|
||||||
```
|
```
|
||||||
{% endfor %}
|
</content>
|
||||||
|
</selected_code>
|
||||||
CODE:
|
{%- endif %}
|
||||||
```{{code_lang}}
|
|
||||||
{{selected_code}}
|
|
||||||
```
|
|
||||||
{%- else -%}
|
|
||||||
{% for file in selected_files %}
|
|
||||||
FILEPATH: {{file.path}}
|
|
||||||
|
|
||||||
CODE:
|
|
||||||
```{{file.file_type}}
|
|
||||||
{{file.content}}
|
|
||||||
```
|
|
||||||
{% endfor %}
|
|
||||||
{%- endif %}{%- endif %}
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
{%- if use_xml_format -%}
|
|
||||||
{%- if diagnostics -%}
|
{%- if diagnostics -%}
|
||||||
<diagnostic_field_description>
|
<diagnostic_field_description>
|
||||||
content: The diagnostic content
|
content: The diagnostic content
|
||||||
@@ -11,16 +10,3 @@ source: The source of the diagnostic
|
|||||||
{{diagnostics}}
|
{{diagnostics}}
|
||||||
</diagnostics>
|
</diagnostics>
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
{%- else -%}
|
|
||||||
{%- if diagnostics -%}
|
|
||||||
DIAGNOSTIC_FIELD_DESCRIPTION:
|
|
||||||
content: The diagnostic content
|
|
||||||
start_line: The starting line of the diagnostic (1-indexed)
|
|
||||||
end_line: The final line of the diagnostic (1-indexed)
|
|
||||||
severity: The severity of the diagnostic
|
|
||||||
source: The source of the diagnostic
|
|
||||||
|
|
||||||
DIAGNOSTICS:
|
|
||||||
{{diagnostics}}
|
|
||||||
{%- endif %}
|
|
||||||
{%- endif %}
|
|
||||||
|
|||||||
@@ -1,12 +1,5 @@
|
|||||||
{%- if use_xml_format -%}
|
|
||||||
{%- if project_context -%}
|
{%- if project_context -%}
|
||||||
<project_context>
|
<project_context>
|
||||||
{{project_context}}
|
{{project_context}}
|
||||||
</project_context>
|
</project_context>
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
{%- else -%}
|
|
||||||
{%- if project_context -%}
|
|
||||||
PROJECT CONTEXT:
|
|
||||||
{{project_context}}
|
|
||||||
{%- endif %}
|
|
||||||
{%- endif %}
|
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ Don't directly search for code context in historical messages. Instead, prioriti
|
|||||||
Tools Usage Guide:
|
Tools Usage Guide:
|
||||||
- You have access to tools, but only use them when necessary. If a tool is not required, respond as normal.
|
- You have access to tools, but only use them when necessary. If a tool is not required, respond as normal.
|
||||||
- Please DON'T be so aggressive in using tools, as many tasks can be better completed without tools.
|
- Please DON'T be so aggressive in using tools, as many tasks can be better completed without tools.
|
||||||
- Files will be provided to you as context through <filepath> and <code> tags!
|
- Files will be provided to you as context through <selected_files> tag!
|
||||||
- If you need to read a file that is already in the context, do not use the `read_file` tool again; directly use the content from the context.
|
- Before using the `read_file` tool each time, always repeatedly check whether the file is already in the <selected_files> tag. If it is already there, do not use the `read_file` tool, just read the file content directly from the <selected_files> tag.
|
||||||
- If the `rag_search` tool exists, prioritize using it to do the search!
|
- If the `rag_search` tool exists, prioritize using it to do the search!
|
||||||
- If the `rag_search` tool exists, only use tools like `search_keyword` `search_files` `read_file` `list_files` etc when absolutely necessary!
|
- If the `rag_search` tool exists, only use tools like `search_keyword` `search_files` `read_file` `list_files` etc when absolutely necessary!
|
||||||
- Keep the `query` parameter of `rag_search` tool as concise as possible! Try to keep it within five English words!
|
- Keep the `query` parameter of `rag_search` tool as concise as possible! Try to keep it within five English words!
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
{# Uses https://mitsuhiko.github.io/minijinja-playground/ for testing:
|
{# Uses https://mitsuhiko.github.io/minijinja-playground/ for testing:
|
||||||
{
|
{
|
||||||
"ask": true,
|
"ask": true,
|
||||||
"use_xml_format": true,
|
|
||||||
"question": "Refactor to include tab flow",
|
"question": "Refactor to include tab flow",
|
||||||
"code_lang": "lua",
|
"code_lang": "lua",
|
||||||
"file_content": "local Config = require('avante.config')"
|
"file_content": "local Config = require('avante.config')"
|
||||||
|
|||||||
@@ -137,11 +137,7 @@ Keep *SEARCH/REPLACE* blocks concise.
|
|||||||
Break large *SEARCH/REPLACE* blocks into a series of smaller blocks that each change a small portion of the file.
|
Break large *SEARCH/REPLACE* blocks into a series of smaller blocks that each change a small portion of the file.
|
||||||
Include just the changing lines, and a few surrounding lines if needed for uniqueness.
|
Include just the changing lines, and a few surrounding lines if needed for uniqueness.
|
||||||
Do not include long runs of unchanging lines in *SEARCH/REPLACE* blocks.
|
Do not include long runs of unchanging lines in *SEARCH/REPLACE* blocks.
|
||||||
{% if use_xml_format -%}
|
|
||||||
ONLY change the <code>, DO NOT change the <context>!
|
ONLY change the <code>, DO NOT change the <context>!
|
||||||
{% else -%}
|
|
||||||
ONLY change the CODE, DO NOT change the CONTEXT!
|
|
||||||
{% endif %}
|
|
||||||
Only create *SEARCH/REPLACE* blocks for files that the user has added to the chat!
|
Only create *SEARCH/REPLACE* blocks for files that the user has added to the chat!
|
||||||
|
|
||||||
To move code within a file, use 2 *SEARCH/REPLACE* blocks: 1 to delete it from its current location, 1 to insert it in the new location.
|
To move code within a file, use 2 *SEARCH/REPLACE* blocks: 1 to delete it from its current location, 1 to insert it in the new location.
|
||||||
|
|||||||
@@ -266,7 +266,6 @@ vim.g.avante_login = vim.g.avante_login
|
|||||||
---@field is_env_set fun(): boolean
|
---@field is_env_set fun(): boolean
|
||||||
---@field api_key_name string
|
---@field api_key_name string
|
||||||
---@field tokenizer_id string | "gpt-4o"
|
---@field tokenizer_id string | "gpt-4o"
|
||||||
---@field use_xml_format boolean
|
|
||||||
---@field model? string
|
---@field model? string
|
||||||
---@field parse_api_key fun(): string | nil
|
---@field parse_api_key fun(): string | nil
|
||||||
---@field parse_stream_data? AvanteStreamParser
|
---@field parse_stream_data? AvanteStreamParser
|
||||||
@@ -286,18 +285,22 @@ vim.g.avante_login = vim.g.avante_login
|
|||||||
---
|
---
|
||||||
---@alias AvanteLlmMode "planning" | "editing" | "suggesting" | "cursor-planning" | "cursor-applying"
|
---@alias AvanteLlmMode "planning" | "editing" | "suggesting" | "cursor-planning" | "cursor-applying"
|
||||||
---
|
---
|
||||||
---@class AvanteSelectedFiles
|
---@class AvanteSelectedCode
|
||||||
|
---@field path string
|
||||||
|
---@field content string
|
||||||
|
---@field file_type string
|
||||||
|
---
|
||||||
|
---@class AvanteSelectedFile
|
||||||
---@field path string
|
---@field path string
|
||||||
---@field content string
|
---@field content string
|
||||||
---@field file_type string
|
---@field file_type string
|
||||||
---
|
---
|
||||||
---@class AvanteTemplateOptions
|
---@class AvanteTemplateOptions
|
||||||
---@field use_xml_format boolean | nil
|
|
||||||
---@field ask boolean
|
---@field ask boolean
|
||||||
---@field code_lang string
|
---@field code_lang string
|
||||||
---@field selected_code string | nil
|
---@field selected_code AvanteSelectedCode | nil
|
||||||
---@field project_context string | nil
|
---@field project_context string | nil
|
||||||
---@field selected_files AvanteSelectedFiles[] | nil
|
---@field selected_files AvanteSelectedFile[] | nil
|
||||||
---@field diagnostics string | nil
|
---@field diagnostics string | nil
|
||||||
---@field history_messages AvanteLLMMessage[] | nil
|
---@field history_messages AvanteLLMMessage[] | nil
|
||||||
---@field memory string | nil
|
---@field memory string | nil
|
||||||
|
|||||||
@@ -275,8 +275,10 @@ function M.get_visual_selection_and_range()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
if not content then return nil end
|
if not content then return nil end
|
||||||
|
local filepath = fn.expand("%:p")
|
||||||
|
local filetype = M.get_filetype(filepath)
|
||||||
-- Return the selected content and range
|
-- Return the selected content and range
|
||||||
return SelectionResult:new(content, range)
|
return SelectionResult:new(filepath, filetype, content, range)
|
||||||
end
|
end
|
||||||
|
|
||||||
---Wrapper around `api.nvim_buf_get_lines` which defaults to the current buffer
|
---Wrapper around `api.nvim_buf_get_lines` which defaults to the current buffer
|
||||||
@@ -637,6 +639,9 @@ function M.is_same_file_ext(target_ext, filepath)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Get recent filepaths in the same project and same file ext
|
-- Get recent filepaths in the same project and same file ext
|
||||||
|
---@param limit? integer
|
||||||
|
---@param filenames? string[]
|
||||||
|
---@return string[]
|
||||||
function M.get_recent_filepaths(limit, filenames)
|
function M.get_recent_filepaths(limit, filenames)
|
||||||
local project_root = M.get_project_root()
|
local project_root = M.get_project_root()
|
||||||
local current_ext = fn.expand("%:e")
|
local current_ext = fn.expand("%:e")
|
||||||
|
|||||||
Reference in New Issue
Block a user