forked from gsuuon/model.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathollama.lua
57 lines (49 loc) · 1.24 KB
/
ollama.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
local util = require('model.util')
local curl = require('model.util.curl')
local juice = require('model.util.juice')
---@type Provider
return {
request_completion = function (handlers, params)
local stop_marquee = juice.handler_marquee_or_notify(
'ollama: ' .. params.model,
handlers.segment,
nil,
20
)
return curl.stream(
{
url = 'http://localhost:11434/api/generate',
headers = {
['Content-Type'] = 'application/json'
},
body = vim.tbl_extend(
'force',
{ raw = true }, -- can override raw
params,
{ stream = true } -- can't override stream
)
},
function(data)
stop_marquee()
local item, error = util.json.decode(data)
if item == nil then
util.eshow(error)
return
end
if item.response then
handlers.on_partial(item.response)
end
if item.done then
handlers.on_finish()
end
if item.error then
handlers.on_error(item.error, 'ollama error')
end
end,
function(err)
stop_marquee()
handlers.on_error(vim.inspect(err), 'Ollama provider error')
end
)
end
}