llm.vim 796 B

12345678910111213141516171819202122232425
  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":10,"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. " Insert the content at the cursor position
  15. call setline(line('.'), getline('.') . content)
  16. endfunction
  17. command! Llm call Llm()