`extract_markdown` transform fails on vim.notify
gordon-quad opened this issue · 1 comments
gordon-quad commented
When I try to use following config
require('model').setup({
prompts = {
provider = llamacpp,
options = {
url = llamacpp_url
},
builder = function(input)
local text, directive = match_llm_directive(input)
local prompt = '<|system|>'
.. instruct_code
.. '\n</s>\n'
prompt = prompt .. '<|user|>\n'
.. text
.. '\n</s>\n'
if directive then
prompt = prompt .. '<|user|>\n'
.. directive
.. '\n</s>\n'
end
return {
prompt = prompt,
stops = { '</s>' }
}
end,
mode = 'replace',
transform = extract.markdown_code,
}
}
})
extract.markdown_code
fails with following error:
E5560: nvim_echo must not be called in a lua loop callback
at line https://github.com/gsuuon/model.nvim/blob/main/lua/model/prompts/extract.lua#L56
Quick fix seems to solve the issue, however I'm not sure if that is 100% correct way to solve it
diff --git a/lua/model/prompts/extract.lua b/lua/model/prompts/extract.lua
index 6e8e715..2dc3fed 100644
--- a/lua/model/prompts/extract.lua
+++ b/lua/model/prompts/extract.lua
@@ -53,7 +53,9 @@ function M.markdown_code(md_text)
local code_blocks = vim.tbl_filter(function(block)
if block.text ~= nil then
- vim.notify(block.text)
+ vim.schedule(function()
+ vim.notify(block.text)
+ end)
end
return block.code ~= nil
end, blocks)
gsuuon commented
@gordon-quad I just pushed a commit that should fix this