forked from gsuuon/model.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtogether.lua
40 lines (37 loc) · 1.1 KB
/
together.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
local util = require('model.util')
local sse = require('model.util.sse')
--- https://docs.together.ai/docs/inference-models
--- https://docs.together.ai/docs/inference-parameters
---@type Provider
local M = {
request_completion = function (handler, params)
return sse.curl_client(
{
url = 'https://api.together.xyz/inference',
headers = {
['Authorization'] = 'Bearer ' .. util.env('TOGETHER_API_KEY'),
['Accept'] = 'application/json',
['Content-Type'] = 'application/json'
},
body = vim.tbl_extend('force', params, {
stream = true
})
},
{
on_message = function (msg, pending)
local item = util.json.decode(msg.data)
if item and item.choices then
handler.on_partial(item.choices[1].text)
elseif msg.data == '[DONE]' then
handler.on_finish()
else
handler.on_error(pending, 'Unrecognized SSE response')
end
end,
on_error = handler.on_error,
on_other = handler.on_error
}
)
end
}
return M