fix(suggestions): cleanup response to ensure JSON (#900)
LLM is not always smart enough to follow the prompt
This commit is contained in:
parent
7413d5a508
commit
97f04f87f5
@ -85,7 +85,10 @@ function Suggestion:suggest()
|
|||||||
vim.schedule(function()
|
vim.schedule(function()
|
||||||
local cursor_row, cursor_col = Utils.get_cursor_pos()
|
local cursor_row, cursor_col = Utils.get_cursor_pos()
|
||||||
if cursor_row ~= doc.position.row or cursor_col ~= doc.position.col then return end
|
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")
|
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)
|
local ok, suggestions = pcall(vim.json.decode, full_response)
|
||||||
if not ok then
|
if not ok then
|
||||||
Utils.error("Error while decoding suggestions: " .. full_response, { once = true, title = "Avante" })
|
Utils.error("Error while decoding suggestions: " .. full_response, { once = true, title = "Avante" })
|
||||||
|
Loading…
x
Reference in New Issue
Block a user