Skip to content

Commit

Permalink
fix: support for ollama 0.1.10
Browse files Browse the repository at this point in the history
  • Loading branch information
David-Kunz committed Nov 20, 2023
1 parent 6d00ea2 commit 501fe1f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 55 deletions.
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@

Generate text using LLMs with customizable prompts

# Important: Issue with ollama 0.1.10

Currently, there are issues with Ollama 0.1.10, please use a previous version instead.
See https://github.com/David-Kunz/gen.nvim/issues/32 for more information.

## Video

[![Local LLMs in Neovim: gen.nvim](https://user-images.githubusercontent.com/1009936/273126287-7b5f2b40-c678-47c5-8f21-edf9516f6034.jpg)](https://youtu.be/FIZt7MinpMY?si=KChSuJJDyrcTdYiM)
Expand Down
70 changes: 20 additions & 50 deletions lua/gen/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -140,59 +140,29 @@ M.exec = function(options)
local float_win = vim.api.nvim_open_win(result_buffer, true, win_opts)

local result_string = ''
local lines = {}
local job_id
job_id = vim.fn.jobstart(cmd, {
on_stdout = function(_, data, _)
-- window was closed, so cancel the job
if not vim.api.nvim_win_is_valid(float_win) then
vim.fn.jobstop(job_id)
return
end
result_string = result_string .. table.concat(data, '\n')
lines = vim.split(result_string, '\n', true)
vim.api.nvim_buf_set_lines(result_buffer, 0, -1, false, lines)
vim.api.nvim_win_call(float_win, function()
vim.fn.feedkeys('$')
end)
end,
on_stderr = function(_, data, _)
if opts.debugCommand then
-- window was closed, so cancel the job
if not vim.api.nvim_win_is_valid(float_win) then
vim.fn.jobstop(job_id)
return
end
result_string = result_string .. table.concat(data, '\n')
lines = vim.split(result_string, '\n', true)
vim.api.nvim_buf_set_lines(result_buffer, 0, -1, false, lines)
vim.api.nvim_win_call(float_win, function()
vim.fn.feedkeys('$')
end)
end
end,
stderr_buffered = opts.debugCommand,
vim.api.nvim_buf_call(result_buffer, function()
vim.fn.termopen(cmd, {
on_exit = function(a, b)
if b == 0 and opts.replace then
if extractor then
local extracted = result_string:match(extractor)
if not extracted then
vim.cmd('bd ' .. result_buffer)
return
end
lines = vim.split(extracted, '\n', true)
end
lines = trim_table(lines)
vim.api.nvim_buf_set_text(curr_buffer, start_pos[2] - 1,
start_pos[3] - 1, end_pos[2] - 1,
end_pos[3] - 1, lines)
vim.cmd('bd ' .. result_buffer)
end
if b == 0 and opts.replace then
local lines = trim_table(vim.api.nvim_buf_get_lines(result_buffer, 0, -1, false))
local text = table.concat(lines, '\n')
if extractor then
local extracted = text:match(extractor)
if not extracted then
vim.cmd('bd ' .. result_buffer)
return
end
lines = vim.split(extracted, '\n', true)
end
vim.api.nvim_buf_set_text(curr_buffer, start_pos[2] - 1,
start_pos[3] - 1, end_pos[2] - 1,
end_pos[3] - 1, lines)
vim.cmd('bd ' .. result_buffer)
end
end
})
vim.keymap.set('n', '<esc>', function() vim.fn.jobstop(job_id) end,
{buffer = result_buffer})

})
end)
vim.api.nvim_buf_attach(result_buffer, false,
{on_detach = function() result_buffer = nil end})

Expand Down

0 comments on commit 501fe1f

Please sign in to comment.