Skip to content

Commit

Permalink
fix(suggestions): cleanup response to ensure JSON (yetone#900)
Browse files Browse the repository at this point in the history
LLM is not always smart enough to follow the prompt
  • Loading branch information
radwo authored Nov 25, 2024
1 parent 7413d5a commit 97f04f8
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lua/avante/suggestion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ function Suggestion:suggest()
vim.schedule(function()
local cursor_row, cursor_col = Utils.get_cursor_pos()
if cursor_row ~= doc.position.row or cursor_col ~= doc.position.col then return end
-- Clean up markdown code blocks
full_response = full_response:gsub("^```%w*\n(.-)\n```$", "%1")
-- Remove everything before the first '[' to ensure we get just the JSON array
full_response = full_response:gsub("^.-(%[.*)", "%1")
local ok, suggestions = pcall(vim.json.decode, full_response)
if not ok then
Utils.error("Error while decoding suggestions: " .. full_response, { once = true, title = "Avante" })
Expand Down

0 comments on commit 97f04f8

Please sign in to comment.