1
0

llm.vim 921 B

12345678910111213141516171819202122232425262728
  1. " Basic plugin example
  2. function! Llm()
  3. let url = "http://127.0.0.1:8080/completion"
  4. " Get the content of the current buffer
  5. let buffer_content = join(getline(1, '$'), "\n")
  6. " Create the JSON payload
  7. 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}
  8. let json_payload.prompt = buffer_content
  9. " Define the curl command
  10. let curl_command = 'curl -k -s -X POST -H "Content-Type: application/json" -d @- ' . url
  11. let response = system(curl_command, json_encode(json_payload))
  12. " Extract the content field from the response
  13. let content = json_decode(response).content
  14. let split_newlines = split(content, '\n', 1)
  15. " Insert the content at the cursor position
  16. call setline(line('.'), [ getline('.') . split_newlines[0] ] + split_newlines[1:])
  17. endfunction
  18. command! Llm call Llm()
  19. noremap <F2> :Llm<CR>