@@ 42,9 42,12 @@ specified, as this parameter serves only as a prompt guideline.")
provide code suggestions based on the user's input. The user's code will be
enclosed in markers:
-- `<beginCode>`: Start of the code context
+- `<contextAfterCursor>`: Code context after the cursor
- `<cursorPosition>`: Current cursor location
-- `<endCode>`: End of the code context
+- `<contextBeforeCursor>`: Code context before the cursor
+
+Note that the user's code will be prompted in reverse order: first the code
+after the cursor, then the code before the cursor.
"
"The default prompt for minuet completion")
@@ 71,12 74,12 @@ enclosed in markers:
(defvar minuet-default-fewshots
`((:role "user"
:content "# language: python
-<beginCode>
-def fibonacci(n):
- <cursorPosition>
+<contextAfterCursor>
fib(5)
-<endCode>")
+<contextBeforeCursor>
+def fibonacci(n):
+ <cursorPosition>")
(:role "assistant"
:content " '''
Recursive Fibonacci implementation
@@ 120,15 123,15 @@ fib(5)
(defvar minuet-codestral-options
'(:model "codestral-latest"
- :end_point "https://codestral.mistral.ai/v1/fim/completions"
- :api_key "CODESTRAL_API_KEY"
+ :end-point "https://codestral.mistral.ai/v1/fim/completions"
+ :api-key "CODESTRAL_API_KEY"
:optional nil)
"config options for Minuet Codestral provider")
(defvar minuet-openai-compatible-options
- `(:end_point "https://api.mistral.ai/v1/chat/completions"
- :api_key "MISTRAL_API_KEY"
- :model "open-mistral-nemo"
+ `(:end-point "https://api.groq.com/openai/v1/chat/completions"
+ :api-key "GROQ_API_KEY"
+ :model "llama-3.1-70b-versatile"
:system
(:template minuet-default-system-template
:prompt minuet-default-prompt
@@ 140,8 143,8 @@ fib(5)
(defvar minuet-openai-fim-compatible-options
'(:model "deepseek-coder"
- :end_point "https://api.deepseek.com/beta/completions"
- :api_key "DEEPSEEK_API_KEY"
+ :end-point "https://api.deepseek.com/beta/completions"
+ :api-key "DEEPSEEK_API_KEY"
:name "Deepseek"
:optional nil)
"config options for Minuet OpenAI FIM compatible provider")
@@ 250,6 253,15 @@ is a symbol, return its value. Else return itself."
:after-cursor ,context-after-cursor
:additional ,(format "%s\n%s" (minuet--add-language-comment) (minuet--add-tab-comment)))))
+(defun minuet--make-chat-llm-shot (context)
+ (concat
+ (plist-get context :additional)
+ "\n<contextAfterCursor>\n"
+ (plist-get context :after-cursor)
+ "\n<contextBeforeCursor>\n"
+ (plist-get context :before-cursor)
+ "<cursorPosition>"))
+
(defun minuet--stream-decode (response get-text-fn)
(setq response (split-string response "[\r]?\n"))
(let (result)
@@ 278,14 290,33 @@ is a symbol, return its value. Else return itself."
;; (setq ,response (append ,response (list text)))
(push text ,response)))
+(defun minuet--stream-decode-raw (response get-text-fn)
+ "Decode the raw stream stored in the temp variable create by `minuet--make-process-stream-filter'"
+ (when-let* ((response (nreverse response))
+ (response (apply #'concat response)))
+ (minuet--stream-decode response get-text-fn)))
+
+(defun minuet--handle-chat-completion-timeout (err response get-text-fn name callback)
+ "Handle the timeout error for chat completion. This function will
+decode and send the partial complete response to the callback,and log
+the error"
+ (if (equal (car (plz-error-curl-error err)) 28)
+ (progn
+ (minuet--log (format "%s Request timeout" name))
+ (when-let* ((result (minuet--stream-decode-raw response get-text-fn))
+ (completion-items (minuet--initial-process-completion-items-default result)))
+ (funcall callback completion-items)))
+ (minuet--log (format "An error occured when sending request to %s" name))
+ (minuet--log err)))
+
(defmacro minuet--with-temp-response (&rest body)
"Execute BODY with a temporary response collection.
This macro creates a local variable `--response--' that can be used
to collect process output within the BODY. It's designed to work in
-conjunction with `minuet--make-process-stream-filter`.
-The `--response--` variable is initialized as an empty list and can
+conjunction with `minuet--make-process-stream-filter'.
+The `--response--' variable is initialized as an empty list and can
be used to accumulate text output from a process. After execution,
-`--response--` will contain the collected responses in reverse order."
+`--response--' will contain the collected responses in reverse order."
`(let (--response--) ,@body))
;;;###autoload
@@ 320,7 351,7 @@ be used to accumulate text output from a process. After execution,
(not (equal var ""))))
(defun minuet--codestral-available-p ()
- (minuet--check-env-var (plist-get minuet-codestral-options :api_key)))
+ (minuet--check-env-var (plist-get minuet-codestral-options :api-key)))
(defun minuet--openai-available-p ()
(minuet--check-env-var "OPENAI_API_KEY"))
@@ 330,16 361,16 @@ be used to accumulate text output from a process. After execution,
(defun minuet--openai-compatible-available-p ()
(when-let* ((options minuet-openai-compatible-options)
- (env-var (plist-get options :api_key))
- (end-point (plist-get options :end_point))
+ (env-var (plist-get options :api-key))
+ (end-point (plist-get options :end-point))
(model (plist-get options :model)))
(minuet--check-env-var env-var)))
(defun minuet--openai-fim-compatible-available-p ()
(when-let* ((options minuet-openai-fim-compatible-options)
- (env-var (plist-get options :api_key))
+ (env-var (plist-get options :api-key))
(name (plist-get options :name))
- (end-point (plist-get options :end_point))
+ (end-point (plist-get options :end-point))
(model (plist-get options :model)))
(minuet--check-env-var env-var)))
@@ 397,10 428,10 @@ be used to accumulate text output from a process. After execution,
completion-items)
(dotimes (_ total-try)
(minuet--with-temp-response
- (plz 'post (plist-get options :end_point)
+ (plz 'post (plist-get options :end-point)
:headers `(("Content-Type" . "application/json")
("Accept" . "application/json")
- ("Authorization" . ,(concat "Bearer " (getenv (plist-get options :api_key)))))
+ ("Authorization" . ,(concat "Bearer " (getenv (plist-get options :api-key)))))
:timeout minuet-request-timeout
:body (json-serialize `(,@(plist-get options :optional)
:stream t
@@ 423,12 454,10 @@ be used to accumulate text output from a process. After execution,
(lambda (err)
(setq try (1+ try))
(if (equal (car (plz-error-curl-error err)) 28)
- (when-let* ((response --response--)
- (response (nreverse --response--))
- (response (apply #'concat response))
- (result (minuet--stream-decode response get-text-fn)))
+ (progn
(minuet--log (format "%s Request timeout" name))
- (push result completion-items)
+ (when-let* ((result (minuet--stream-decode-raw --response-- get-text-fn)))
+ (push result completion-items))
(when (>= try total-try)
(funcall callback completion-items)))
(minuet--log (format "An error occured when sending request to %s" name))
@@ 463,10 492,10 @@ be used to accumulate text output from a process. After execution,
(defun minuet--openai-complete-base (options context callback)
(minuet--with-temp-response
- (plz 'post (plist-get options :end_point)
+ (plz 'post (plist-get options :end-point)
:headers `(("Content-Type" . "application/json")
("Accept" . "application/json")
- ("Authorization" . ,(concat "Bearer " (getenv (plist-get options :api_key)))))
+ ("Authorization" . ,(concat "Bearer " (getenv (plist-get options :api-key)))))
:timeout minuet-request-timeout
:body (json-serialize `(,@(plist-get options :optional)
:stream t
@@ 476,13 505,7 @@ be used to accumulate text output from a process. After execution,
:content ,(minuet--make-system-prompt (plist-get options :system)))
,@(minuet--eval-value (plist-get options :few_shots))
(:role "user"
- :content ,(concat
- (plist-get context :additional)
- "\n<beginCode>\n"
- (plist-get context :before-cursor)
- "<cursorPosition>"
- (plist-get context :after-cursor)
- "<endCode>"))))))
+ :content ,(minuet--make-chat-llm-shot context))))))
:as 'string
:filter (minuet--make-process-stream-filter --response--)
:then
@@ 491,24 514,16 @@ be used to accumulate text output from a process. After execution,
(completion-items (minuet--initial-process-completion-items-default result)))
;; insert the current result into the completion items list
(funcall callback completion-items)))
- :else (lambda (err)
- ;; we want to collect the partial compleetion items when request timeout
- (if (equal (car (plz-error-curl-error err)) 28)
- (when-let* ((response --response--)
- (response (nreverse --response--))
- (response (apply #'concat response))
- (result (minuet--stream-decode response #'minuet--openai-get-text-fn))
- (completion-items (minuet--initial-process-completion-items-default result)))
- (minuet--log "OpenAI Request timeout")
- (funcall callback completion-items))
- (minuet--log "An error occured when sending request to OpenAI")
- (minuet--log err))))))
+ :else
+ (lambda (err)
+ (minuet--handle-chat-completion-timeout
+ err --response-- #'minuet--openai-get-text-fn "OpenAI" callback)))))
(defun minuet--openai-complete (context callback)
(minuet--openai-complete-base
(--> (copy-tree minuet-openai-options)
- (plist-put it :end_point "https://api.openai.com/v1/chat/completions")
- (plist-put it :api_key "OPENAI_API_KEY"))
+ (plist-put it :end-point "https://api.openai.com/v1/chat/completions")
+ (plist-put it :api-key "OPENAI_API_KEY"))
context callback))
(defun minuet--openai-compatible-complete (context callback)
@@ 537,13 552,7 @@ be used to accumulate text output from a process. After execution,
:messages ,(vconcat
`(,@(minuet--eval-value (plist-get options :few_shots))
(:role "user"
- :content ,(concat
- (plist-get context :additional)
- "\n<beginCode>\n"
- (plist-get context :before-cursor)
- "<cursorPosition>"
- (plist-get context :after-cursor)
- "<endCode>")))))))
+ :content ,(minuet--make-chat-llm-shot context)))))))
:as 'string
:filter (minuet--make-process-stream-filter --response--)
:then
@@ 552,18 561,10 @@ be used to accumulate text output from a process. After execution,
(completion-items (minuet--initial-process-completion-items-default result)))
;; insert the current result into the completion items list
(funcall callback completion-items)))
- :else (lambda (err)
- ;; we want to collect the partial compleetion items when request timeout
- (if (equal (car (plz-error-curl-error err)) 28)
- (when-let* ((response --response--)
- (response (nreverse --response--))
- (response (apply #'concat response))
- (result (minuet--stream-decode response #'minuet--claude-get-text-fn))
- (completion-items (minuet--initial-process-completion-items-default result)))
- (minuet--log "Claude Request timeout")
- (funcall callback completion-items))
- (minuet--log "An error occured when sending request to Claude")
- (minuet--log err))))))
+ :else
+ (lambda (err)
+ (minuet--handle-chat-completion-timeout
+ err --response-- #'minuet--claude-get-text-fn "Claude" callback)))))
(defun minuet--gemini-get-text-fn (json)
(--> json
@@ 597,14 598,7 @@ be used to accumulate text output from a process. After execution,
:contents ,(vconcat
`(,@few_shots
(:role "user"
- :parts [(:text
- ,(concat
- (plist-get context :additional)
- "\n<beginCode>\n"
- (plist-get context :before-cursor)
- "<cursorPosition>"
- (plist-get context :after-cursor)
- "<endCode>"))]))))))
+ :parts [(:text ,(minuet--make-chat-llm-shot context))]))))))
:as 'string
:filter (minuet--make-process-stream-filter --response--)
:then
@@ 613,18 607,10 @@ be used to accumulate text output from a process. After execution,
(completion-items (minuet--initial-process-completion-items-default result)))
;; insert the current result into the completion items list
(funcall callback completion-items)))
- :else (lambda (err)
- ;; we want to collect the partial compleetion items when request timeout
- (if (equal (car (plz-error-curl-error err)) 28)
- (when-let* ((response --response--)
- (response (nreverse --response--))
- (response (apply #'concat response))
- (result (minuet--stream-decode response #'minuet--gemini-get-text-fn))
- (completion-items (minuet--initial-process-completion-items-default result)))
- (minuet--log "Gemini Request timeout")
- (funcall callback completion-items))
- (minuet--log "An error occured when sending request to Gemini")
- (minuet--log err))))))
+ :else
+ (lambda (err)
+ (minuet--handle-chat-completion-timeout
+ err --response-- #'minuet--gemini-get-text-fn "Gemini" callback)))))
(provide 'minuet)
;;; minuet.el ends here
@@ 1,35 1,35 @@
-(("ESS" . "e4f2afb90d11613c4c2a28720dcda226699b4dfb")
+(("ESS" . "950bf61054bd96d2203ac0457792c0af8dfba721")
("Emacs-wgrep" . "208b9d01cfffa71037527e3a324684b3ce45ddc4")
("annalist.el" . "e1ef5dad75fa502d761f70d9ddf1aeb1c423f41d")
("anzu" . "26fb50b429ee968eb944b0615dd0aed1dd66172c")
("better-jumper" . "47622213783ece37d5337dc28d33b530540fc319")
("cape" . "5c468d6d657e8dc604ddf3feb80f70e1e05ac0a1")
("citre" . "d99483767016cada88a2877a77b9b76f8e118b80")
- ("code-cells.el" . "44546ca256f3da29e3ac884e3d699c8455acbd6e")
+ ("code-cells.el" . "c2820dcf99ec2fdb0130daddc37f3fb48611fb8b")
("company-box" . "c4f2e243fba03c11e46b1600b124e036f2be7691")
- ("company-mode" . "8bd34f8e73957bb7d5234564a45175c171016e63")
- ("compat" . "3c782506419b937d9e30b01ceb1cd49e7a4e7842")
+ ("company-mode" . "1321e285a54dfe43cae71f52e58bff4f0c8c161d")
+ ("compat" . "99d74e635b76c3fa0b8403391e9d2efbd29f9901")
("consult" . "4889458dccf842ab6223099f8a73ff8b147e9459")
("consult-dir" . "15891383f34d43acc5bb82bda92239b1f54cf178")
("consult-eglot" . "64262e72452f8fe6dd49d31bcdd4bd577b7d682d")
("consult-notmuch" . "d8022e2ddc67ed4e89cc6f5bbe664fdb04e1e815")
("dape" . "67945a9ac45a5c35624a093951fb3ae0cab35850")
("dash.el" . "1de9dcb83eacfb162b6d9a118a4770b1281bcd84")
- ("diff-hl" . "57d9d4e3e17397bf178c3aa5c369b5edd24523e0")
+ ("diff-hl" . "b80ff9b4a772f7ea000e86fbf88175104ddf9557")
("dired-git-info" . "578b32f6287911e950c79e285a7b8088337de020")
("dired-hacks" . "e9e408e8571aee5574ca0a431ef15cac5a3585d4")
("dired-rsync" . "5bcb851f3bf9c4f7c07299fcc25be7c408a68cda")
("dired-sidebar" . "702165ad53a473992d84e0207b984b9be5114bde")
("diredfl" . "f6d599c30875ab4894c1deab9713ff2faea54e06")
- ("doom-modeline" . "b782f3c31b966c43fa281fd5fdd07d5c11579e25")
+ ("doom-modeline" . "207f69ded9ac8d754cb84ff4466dcdef338c92c6")
("edit-indirect" . "82a28d8a85277cfe453af464603ea330eae41c05")
("ef-themes" . "5e902f286bc052bcc200826d0677bd17f8f21b12")
("el-get" . "c0713e8d8e8ad987fe1283d76b9c637a10f048ef")
- ("elfeed" . "5c05a1eab37bc113ecb158a4d57fe05352fa2c6a")
+ ("elfeed" . "904b6d4feca78e7e5336d7dbb7b8ba53b8c4dac1")
("elfeed-org" . "d62d23e25c5e3be3d70b7fbe1eaeb6e43f93a061")
("elisp-demos" . "1a108d1c5011f9ced58be2ca98bea1fbd4130a2f")
("elisp-refs" . "541a064c3ce27867872cf708354a65d83baf2a6d")
- ("emacs-async" . "20f7757c08d998c79ca6c9d724c0500281dd512b")
+ ("emacs-async" . "67613344e153009ac9afb96b455130b7d27ba361")
("emacs-htmlize" . "ed5e5b05fd260e8f161a488d56f10e7f6e01fb75")
("emacs-libvterm" . "d9ea29fb10aed20512bd95dc5b8c1a01684044b1")
("emacs-reformatter" . "0d29a04d69d47599e2cb7f1a8f8e897a2b592921")
@@ 37,13 37,13 @@
("emacs-websocket" . "40c208eaab99999d7c1e4bea883648da24c03be3")
("emacs-which-key" . "38d4308d1143b61e4004b6e7a940686784e51500")
("emacs-zmq" . "1d9d5a3b46cfd1a90a45ff777f200eb4d5d6fd9e")
- ("emacsmirror-mirror" . "c68396ffe5fb691731881101ab1269b54d1a203e")
+ ("emacsmirror-mirror" . "b1e50f90d305c20752237dbf764920c656a2124e")
("embark" . "19a13e344e04bbf861eaa74491b23da52b398672")
("embrace.el" . "c7e748603151d7d91c237fd2d9cdf56e9f3b1ea8")
("evil" . "30ebe6df27c36fdf2ea3c82a916edec31acc2647")
("evil-anzu" . "d1e98ee6976437164627542909a25c6946497899")
("evil-args" . "a8151556f63c9d45d0c44c8a7ef9e5a542f3cdc7")
- ("evil-collection" . "28d64031ff58871828a0dec25ef437beb9371337")
+ ("evil-collection" . "e49d8e96ccc83d2bf7583c124582fc1ef076b15c")
("evil-embrace.el" . "3081d37811b6a3dfaaf01d578c7ab7a746c6064d")
("evil-escape" . "bdb1e69971520cbd65fe61830a1cdea5734d743c")
("evil-exchange" . "5f0a2d41434c17c6fb02e4f744043775de1c63a2")
@@ 65,26 65,26 @@
("f.el" . "1e7020dc0d4c52d3da9bd610d431cab13aa02d8c")
("frame-local" . "7ee1106c3bcd4022f48421f8cb1ef4f995da816e")
("general.el" . "826bf2b97a0fb4a34c5eb96ec2b172d682fd548f")
- ("gnu-elpa-mirror" . "c7c879e92cb2cfe5af56b8877d24a1d9b2adf14e")
+ ("gnu-elpa-mirror" . "3d0759ef4792b6461f2979a4e70e1c819df7283a")
("goto-chg" . "72f556524b88e9d30dc7fc5b0dc32078c166fda7")
("helpful" . "4ba24cac9fb14d5fdc32582cd947572040e82b2c")
("highlight-quoted" . "24103478158cd19fbcfb4339a3f1fa1f054f1469")
- ("hl-todo" . "aa58c45a78c64bb8d5509120c775a33b4b2c6aa2")
+ ("hl-todo" . "82eba6b8f7b5a4cbcf22436d5c5b88fb3134f57e")
("ibuffer-vc" . "66d02267334f536e978ed7f384f88bd04a3d4dbb")
("jsonrpc" . "cd597b048e2a380c5f4ebfa3bbab90848275a294")
("jupyter" . "f97f4b5d8c83e0b901020f835183dde8a2bf649e")
("let-alist" . "4e05e158612f360f6080b1349d3962b1c8fee902")
("macrostep" . "4939d88779761e8b5461b4cf73f86600172987db")
- ("magit" . "6cd698d36ae44e806857a667143f2253d27a6ac2")
+ ("magit" . "020aca7c9c4154dbc4a72acbd56165ecccea1bf1")
("marginalia" . "7a7f3363d042d1bf43ae697f4401638ed18230a5")
("markdown-mode" . "8a7773f87733866a961ea4c518a4a2f283f21970")
- ("melpa" . "ae45333491f24e0ecb5945db6e929b56e737e260")
+ ("melpa" . "9875de56d4c4f5e1d6f127a0b2e408e87a9dd932")
("nerd-icons-completion" . "426a1d7c29a04ae8e6ae9b55b0559f11a1e8b420")
("nerd-icons-dired" . "c1c73488630cc1d19ce1677359f614122ae4c1b9")
("nerd-icons-ibuffer" . "16270e898abbba2bd810cbf97f999c6142863101")
- ("nerd-icons.el" . "4322290303f2e12efd5685a0d22d76ed76ec7349")
+ ("nerd-icons.el" . "dcfc64152ada7514bcdd1c6ce45590c359445ec6")
("nongnu-elpa" . "f031337c6ee125455a98e2de899a563388e5de19")
- ("ol-notmuch" . "44369674e674aa5d8d7805aa7e279bc15b462d80")
+ ("ol-notmuch" . "437aab56192ea86a52738fa5e9216c006df80bd0")
("orderless" . "49d1fdfb80b55699a00b11bc916ad29c0447039b")
("org-appear" . "32ee50f8fdfa449bbc235617549c1bccb503cb09")
("org-download" . "19e166f0a8c539b4144cfbc614309d47a9b2a9b7")
@@ 100,14 100,14 @@
("shrink-path.el" . "c14882c8599aec79a6e8ef2d06454254bb3e1e41")
("spacemacs-theme" . "3cc6919d63726e96653169a7846aa5eca06e9a8b")
("sql-indent" . "99d6d9b1144e2591c858981a226d70dabf57a1fe")
- ("straight.el" . "b3760f5829dba37e855add7323304561eb57a3d4")
+ ("straight.el" . "88e574ae75344e39b436f863ef0344135c7b6517")
("tablist" . "fcd37147121fabdf003a70279cf86fbe08cfac6f")
- ("themes" . "b6872fa0963cd4ae2e87938563429e82599bb6d4")
- ("transient" . "2a680c21e2be0b055e0e801d43c92792e5305acc")
+ ("themes" . "c589b245d643dcc5ec93054ea436efc5255f9b88")
+ ("transient" . "b2cb4e578f2362a0354c4a31a6bd89d6c4b63d63")
("use-package" . "a6e856418d2ebd053b34e0ab2fda328abeba731c")
("vertico" . "d70fdeb67be9ecc88c438039eefa9ef0e2104005")
("vimish-fold" . "a6501cbfe3db791f9ca17fd986c7202a87f3adb8")
- ("with-editor" . "62dc8ba2184bef074ff0e90eefb70bfa34c21d3c")
+ ("with-editor" . "78c303a0181f2132e2254f965176b549044d74f2")
("ws-butler" . "e3a38d93e01014cd47bf5af4924459bd145fd7c4")
("xclip" . "de4a76f63a6df4fc2bb4ea2eae249a9447f5db7b")
("xref" . "53c4abbc26febcd45be79dea43b7dc56d12112de")