Skip to content

Commit 9cf5ed3

Browse files
authored
Merge pull request #39 from ggml-org/use_stdin
Use stdin when calling curl
2 parents a0dd85c + f2275c5 commit 9cf5ed3

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

autoload/llama.vim

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
" vim: ts=4 sts=4 expandtab
12
" colors (adjust to your liking)
23
highlight llama_hl_hint guifg=#ff772f ctermfg=202
34
highlight llama_hl_info guifg=#77ff2f ctermfg=119
@@ -318,17 +319,22 @@ function! s:ring_update()
318319
\ "--request", "POST",
319320
\ "--url", g:llama_config.endpoint,
320321
\ "--header", "Content-Type: application/json",
321-
\ "--data", l:request
322+
\ "--data", "@-",
322323
\ ]
323324
if exists ("g:llama_config.api_key") && len("g:llama_config.api_key") > 0
324325
call extend(l:curl_command, ['--header', 'Authorization: Bearer ' .. g:llama_config.api_key])
325326
endif
326327

327328
" no callbacks because we don't need to process the response
328329
if s:ghost_text_nvim
329-
call jobstart(l:curl_command, {})
330+
let jobid = jobstart(l:curl_command, {})
331+
call chansend(jobid, l:request)
332+
call chanclose(jobid, 'stdin')
330333
elseif s:ghost_text_vim
331-
call job_start(l:curl_command, {})
334+
let jobid = job_start(l:curl_command, {})
335+
let channel = job_getchannel(jobid)
336+
call ch_sendraw(channel, l:request)
337+
call ch_close_in(channel)
332338
endif
333339
endfunction
334340

@@ -444,7 +450,7 @@ function! llama#fim(is_auto, cache) abort
444450
\ "--request", "POST",
445451
\ "--url", g:llama_config.endpoint,
446452
\ "--header", "Content-Type: application/json",
447-
\ "--data", l:request
453+
\ "--data", "@-",
448454
\ ]
449455
if exists ("g:llama_config.api_key") && len("g:llama_config.api_key") > 0
450456
call extend(l:curl_command, ['--header', 'Authorization: Bearer ' .. g:llama_config.api_key])
@@ -504,11 +510,17 @@ function! llama#fim(is_auto, cache) abort
504510
\ 'on_exit': function('s:fim_on_exit'),
505511
\ 'stdout_buffered': v:true
506512
\ })
513+
call chansend(s:current_job, l:request)
514+
call chanclose(s:current_job, 'stdin')
507515
elseif s:ghost_text_vim
508516
let s:current_job = job_start(l:curl_command, {
509517
\ 'out_cb': function('s:fim_on_stdout', [l:hash, a:cache, s:pos_x, s:pos_y, a:is_auto]),
510518
\ 'exit_cb': function('s:fim_on_exit')
511519
\ })
520+
521+
let channel = job_getchannel(s:current_job)
522+
call ch_sendraw(channel, l:request)
523+
call ch_close_in(channel)
512524
endif
513525
endif
514526

0 commit comments

Comments
 (0)