Skip to content

Commit 7e50de8

Browse files
authored
fix: ReAct tool use format in few-shot (#2542)
1 parent 0a21435 commit 7e50de8

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

crates/avante-templates/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ struct TemplateContext {
4545
memory: Option<String>,
4646
todos: Option<String>,
4747
enable_fastapply: Option<bool>,
48+
use_react_prompt: Option<bool>,
4849
}
4950

5051
// Given the file name registered after add, the context table in Lua, resulted in a formatted
@@ -74,6 +75,7 @@ fn render(state: &State, template: &str, context: TemplateContext) -> LuaResult<
7475
memory => context.memory,
7576
todos => context.todos,
7677
enable_fastapply => context.enable_fastapply,
78+
use_react_prompt => context.use_react_prompt,
7779
})
7880
.map_err(LuaError::external)
7981
.unwrap())

lua/avante/llm.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,8 @@ function M.generate_prompts(opts)
296296

297297
selected_files = vim.iter(selected_files):filter(function(file) return viewed_files[file.path] == nil end):totable()
298298

299+
local provider_conf = Providers.parse_config(provider)
300+
299301
local template_opts = {
300302
ask = opts.ask, -- TODO: add mode without ask instruction
301303
code_lang = opts.code_lang,
@@ -308,6 +310,7 @@ function M.generate_prompts(opts)
308310
model_name = provider.model or "unknown",
309311
memory = opts.memory,
310312
enable_fastapply = Config.behaviour.enable_fastapply,
313+
use_react_prompt = provider_conf.use_ReAct_prompt,
311314
}
312315

313316
-- Removed the original todos processing logic, now handled in context_messages

lua/avante/templates/_tools-guidelines.avanterules

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ TOOLS USAGE GUIDE
3434
**Crucial Example of Correct Behavior:**
3535
* **User Input:** "Hi there"
3636
* **Your REQUIRED Output (as a tool call):**
37+
{% if use_react_prompt -%}
38+
<tool_use>{"name": "attempt_completion", "input": {"result": "[**Generated Response Following the Greeting Response Guideline**]"}}</tool_use>
39+
{% else -%}
3740
```json
3841
{
3942
"tool_calls": [
@@ -47,3 +50,4 @@ TOOLS USAGE GUIDE
4750
]
4851
}
4952
```
53+
{% endif %}

0 commit comments

Comments
 (0)