/ examples / llm.vim
llm.vim
 1  " Basic plugin example
 2  
 3  function! Llm()
 4  
 5    let url = "http://127.0.0.1:8080/completion"
 6  
 7    " Get the content of the current buffer
 8    let buffer_content = join(getline(1, '$'), "\n")
 9  
10    " Create the JSON payload
11    let json_payload = {"temp":0.72,"top_k":100,"top_p":0.73,"repeat_penalty":1.100000023841858,"n_predict":256,"stop": ["\n\n\n"],"stream": v:false}
12    let json_payload.prompt = buffer_content
13  
14    " Define the curl command
15    let curl_command = 'curl -k -s -X POST -H "Content-Type: application/json" -d @- ' . url
16    let response = system(curl_command, json_encode(json_payload))
17  
18    " Extract the content field from the response
19    let content = json_decode(response).content
20  
21    let split_newlines = split(content, '\n', 1)
22  
23    " Insert the content at the cursor position
24    call setline(line('.'), [ getline('.') . split_newlines[0] ] + split_newlines[1:])
25  endfunction
26  
27  command! Llm call Llm()
28  noremap <F2> :Llm<CR>