-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcopilot.fnl
50 lines (39 loc) · 1.44 KB
/
copilot.fnl
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
41
42
43
44
45
46
47
48
49
(module copilot
{autoload {core aniseed.core
nvim aniseed.nvim
str aniseed.string
util slim.nvim
curl plenary.curl}})
(defn open [lines]
(let [buf (vim.api.nvim_create_buf false true)]
(vim.api.nvim_buf_set_text buf 0 0 0 0 lines)
(util.open-win buf {:title "Copilot"})))
(comment
(open ["hey"]))
(defn openselection []
(open (util.get-current-buffer-selection)))
(nvim.set_keymap :v :<leader>ai ":lua require('copilot').openselection()<CR>" {})
;; -------
(defn ollama [system-prompt prompt cb]
(curl.post
"http://localhost:11434/api/generate"
{:body (vim.json.encode {:model "mistral"
:prompt prompt
:system-prompt system-prompt
:stream true})
:stream (fn [_ chunk _]
(cb (. (vim.json.decode chunk) "response"))) }))
(defn execute-prompt [prompt]
(util.stream-into-buffer (partial ollama "") prompt))
(comment
(execute-prompt "What does a Dockerfile look like?")
(vim.fn.input "Question:"))
(defn copilot []
(let [prompt (..
"I have a question about this: "
(vim.fn.input "Question: ")
"\n\n Here is the code:\n```\n"
(str.join "\n" (util.get-current-buffer-selection))
"\n```\n")]
(execute-prompt prompt)))
(nvim.set_keymap :v :<leader>ai ":lua require('copilot').copilot()<CR>" {})