branch: externals/minuet commit c837149120ddff0cbb7a490cc60c513276b9703d Author: Milan Glacier <d...@milanglacier.com> Commit: Milan Glacier <d...@milanglacier.com>
chore: reformat code. --- minuet.el | 292 +++++++++++++++++++++++++++++++------------------------------- 1 file changed, 146 insertions(+), 146 deletions(-) diff --git a/minuet.el b/minuet.el index 05d79c7a26..8651cd3587 100644 --- a/minuet.el +++ b/minuet.el @@ -849,41 +849,41 @@ arrive." completion-items) (dotimes (_ total-try) (minuet--with-temp-response - (push - (plz 'post (plist-get options :end-point) - :headers `(("Content-Type" . "application/json") - ("Accept" . "application/json") - ("Authorization" . ,(concat "Bearer " (minuet--get-api-key (plist-get options :api-key))))) - :timeout minuet-request-timeout - :body body - :as 'string - :filter (minuet--make-process-stream-filter --response--) - :then - (lambda (json) - (when-let* ((result (minuet--stream-decode json get-text-fn))) - ;; insert the current result into the completion items list - (push result completion-items)) - (setq completion-items (minuet--filter-context-sequence-in-items - completion-items - context)) - (setq completion-items (minuet--remove-spaces completion-items)) - (funcall callback completion-items)) - :else - (lambda (err) - (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))) - (push result completion-items))) - (minuet--log (format "An error occured when sending request to %s" name)) - (minuet--log err)) - (setq completion-items - (minuet--filter-context-sequence-in-items - completion-items - context)) - (setq completion-items (minuet--remove-spaces completion-items)) - (funcall callback completion-items))) - minuet--current-requests))))) + (push + (plz 'post (plist-get options :end-point) + :headers `(("Content-Type" . "application/json") + ("Accept" . "application/json") + ("Authorization" . ,(concat "Bearer " (minuet--get-api-key (plist-get options :api-key))))) + :timeout minuet-request-timeout + :body body + :as 'string + :filter (minuet--make-process-stream-filter --response--) + :then + (lambda (json) + (when-let* ((result (minuet--stream-decode json get-text-fn))) + ;; insert the current result into the completion items list + (push result completion-items)) + (setq completion-items (minuet--filter-context-sequence-in-items + completion-items + context)) + (setq completion-items (minuet--remove-spaces completion-items)) + (funcall callback completion-items)) + :else + (lambda (err) + (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))) + (push result completion-items))) + (minuet--log (format "An error occured when sending request to %s" name)) + (minuet--log err)) + (setq completion-items + (minuet--filter-context-sequence-in-items + completion-items + context)) + (setq completion-items (minuet--remove-spaces completion-items)) + (funcall callback completion-items))) + minuet--current-requests))))) (defun minuet--codestral-complete (context callback) "Complete code with codestral. @@ -924,41 +924,41 @@ OPTIONS are the provider options. the completion items from json. CONTEXT is to be used to build the prompt. CALLBACK is the function to be called when completion items arrive." (minuet--with-temp-response - (push - (plz 'post (plist-get options :end-point) - :headers - `(("Content-Type" . "application/json") - ("Accept" . "application/json") - ("Authorization" . ,(concat "Bearer " (minuet--get-api-key (plist-get options :api-key))))) - :timeout minuet-request-timeout - :body - (json-serialize - `(,@(plist-get options :optional) - :stream t - :model ,(plist-get options :model) - :messages ,(vconcat - `((:role "system" - :content ,(minuet--make-system-prompt (plist-get options :system))) - ,@(minuet--eval-value (plist-get options :fewshots)) - (:role "user" - :content ,(minuet--make-chat-llm-shot context options)))))) - :as 'string - :filter (minuet--make-process-stream-filter --response--) - :then - (lambda (json) - (when-let* ((result (minuet--stream-decode json #'minuet--openai-get-text-fn)) - (completion-items (minuet--parse-completion-itmes-default result)) - (completion-items (minuet--filter-context-sequence-in-items - completion-items - context)) - (completion-items (minuet--remove-spaces completion-items))) - ;; insert the current result into the completion items list - (funcall callback completion-items))) - :else - (lambda (err) - (minuet--handle-chat-completion-timeout - context err --response-- #'minuet--openai-get-text-fn "OpenAI" callback))) - minuet--current-requests))) + (push + (plz 'post (plist-get options :end-point) + :headers + `(("Content-Type" . "application/json") + ("Accept" . "application/json") + ("Authorization" . ,(concat "Bearer " (minuet--get-api-key (plist-get options :api-key))))) + :timeout minuet-request-timeout + :body + (json-serialize + `(,@(plist-get options :optional) + :stream t + :model ,(plist-get options :model) + :messages ,(vconcat + `((:role "system" + :content ,(minuet--make-system-prompt (plist-get options :system))) + ,@(minuet--eval-value (plist-get options :fewshots)) + (:role "user" + :content ,(minuet--make-chat-llm-shot context options)))))) + :as 'string + :filter (minuet--make-process-stream-filter --response--) + :then + (lambda (json) + (when-let* ((result (minuet--stream-decode json #'minuet--openai-get-text-fn)) + (completion-items (minuet--parse-completion-itmes-default result)) + (completion-items (minuet--filter-context-sequence-in-items + completion-items + context)) + (completion-items (minuet--remove-spaces completion-items))) + ;; insert the current result into the completion items list + (funcall callback completion-items))) + :else + (lambda (err) + (minuet--handle-chat-completion-timeout + context err --response-- #'minuet--openai-get-text-fn "OpenAI" callback))) + minuet--current-requests))) (defun minuet--openai-complete (context callback) "Complete code with OpenAI. @@ -985,42 +985,42 @@ CONTEXT and CALLBACK will be passed to the base function." CONTEXT is to be used to build the prompt. CALLBACK is the function to be called when completion items arrive." (minuet--with-temp-response - (push - (plz 'post "https://api.anthropic.com/v1/messages" - :headers `(("Content-Type" . "application/json") - ("Accept" . "application/json") - ("x-api-key" . ,(minuet--get-api-key (plist-get minuet-claude-options :api-key))) - ("anthropic-version" . "2023-06-01")) - :timeout minuet-request-timeout - :body - (json-serialize - (let ((options (copy-tree minuet-claude-options))) - `(,@(plist-get options :optional) - :stream t - :model ,(plist-get options :model) - :system ,(minuet--make-system-prompt (plist-get options :system)) - :max_tokens ,(plist-get options :max_tokens) - :messages ,(vconcat - `(,@(minuet--eval-value (plist-get options :fewshots)) - (:role "user" - :content ,(minuet--make-chat-llm-shot context minuet-claude-options))))))) - :as 'string - :filter (minuet--make-process-stream-filter --response--) - :then - (lambda (json) - (when-let* ((result (minuet--stream-decode json #'minuet--claude-get-text-fn)) - (completion-items (minuet--parse-completion-itmes-default result)) - (completion-items (minuet--filter-context-sequence-in-items - completion-items - context)) - (completion-items (minuet--remove-spaces completion-items))) - ;; insert the current result into the completion items list - (funcall callback completion-items))) - :else - (lambda (err) - (minuet--handle-chat-completion-timeout - context err --response-- #'minuet--claude-get-text-fn "Claude" callback))) - minuet--current-requests))) + (push + (plz 'post "https://api.anthropic.com/v1/messages" + :headers `(("Content-Type" . "application/json") + ("Accept" . "application/json") + ("x-api-key" . ,(minuet--get-api-key (plist-get minuet-claude-options :api-key))) + ("anthropic-version" . "2023-06-01")) + :timeout minuet-request-timeout + :body + (json-serialize + (let ((options (copy-tree minuet-claude-options))) + `(,@(plist-get options :optional) + :stream t + :model ,(plist-get options :model) + :system ,(minuet--make-system-prompt (plist-get options :system)) + :max_tokens ,(plist-get options :max_tokens) + :messages ,(vconcat + `(,@(minuet--eval-value (plist-get options :fewshots)) + (:role "user" + :content ,(minuet--make-chat-llm-shot context minuet-claude-options))))))) + :as 'string + :filter (minuet--make-process-stream-filter --response--) + :then + (lambda (json) + (when-let* ((result (minuet--stream-decode json #'minuet--claude-get-text-fn)) + (completion-items (minuet--parse-completion-itmes-default result)) + (completion-items (minuet--filter-context-sequence-in-items + completion-items + context)) + (completion-items (minuet--remove-spaces completion-items))) + ;; insert the current result into the completion items list + (funcall callback completion-items))) + :else + (lambda (err) + (minuet--handle-chat-completion-timeout + context err --response-- #'minuet--claude-get-text-fn "Claude" callback))) + minuet--current-requests))) (defun minuet--gemini-get-text-fn (json) "Function to get the completion from a JSON object for gemini." @@ -1037,46 +1037,46 @@ to be called when completion items arrive." CONTEXT is to be used to build the prompt. CALLBACK is the function to be called when completion items arrive." (minuet--with-temp-response - (push - (plz 'post (format "https://generativelanguage.googleapis.com/v1beta/models/%s:streamGenerateContent?alt=sse&key=%s" - (plist-get minuet-gemini-options :model) - (minuet--get-api-key (plist-get minuet-gemini-options :api-key))) - :headers `(("Content-Type" . "application/json") - ("Accept" . "application/json")) - :timeout minuet-request-timeout - :body - (json-serialize - (let* ((options (copy-tree minuet-gemini-options)) - (fewshots (minuet--eval-value (plist-get options :fewshots))) - (fewshots (mapcar - (lambda (shot) - `(:role - ,(if (equal (plist-get shot :role) "user") "user" "model") - :parts - [(:text ,(plist-get shot :content))])) - fewshots))) - `(,@(plist-get options :optional) - :system_instruction (:parts (:text ,(minuet--make-system-prompt (plist-get options :system)))) - :contents ,(vconcat - `(,@fewshots - (:role "user" - :parts [(:text ,(minuet--make-chat-llm-shot context minuet-gemini-options))])))))) - :as 'string - :filter (minuet--make-process-stream-filter --response--) - :then - (lambda (json) - (when-let* ((result (minuet--stream-decode json #'minuet--gemini-get-text-fn)) - (completion-items (minuet--parse-completion-itmes-default result)) - (completion-items (minuet--filter-context-sequence-in-items - completion-items - context)) - (completion-items (minuet--remove-spaces completion-items))) - (funcall callback completion-items))) - :else - (lambda (err) - (minuet--handle-chat-completion-timeout - context err --response-- #'minuet--gemini-get-text-fn "Gemini" callback))) - minuet--current-requests))) + (push + (plz 'post (format "https://generativelanguage.googleapis.com/v1beta/models/%s:streamGenerateContent?alt=sse&key=%s" + (plist-get minuet-gemini-options :model) + (minuet--get-api-key (plist-get minuet-gemini-options :api-key))) + :headers `(("Content-Type" . "application/json") + ("Accept" . "application/json")) + :timeout minuet-request-timeout + :body + (json-serialize + (let* ((options (copy-tree minuet-gemini-options)) + (fewshots (minuet--eval-value (plist-get options :fewshots))) + (fewshots (mapcar + (lambda (shot) + `(:role + ,(if (equal (plist-get shot :role) "user") "user" "model") + :parts + [(:text ,(plist-get shot :content))])) + fewshots))) + `(,@(plist-get options :optional) + :system_instruction (:parts (:text ,(minuet--make-system-prompt (plist-get options :system)))) + :contents ,(vconcat + `(,@fewshots + (:role "user" + :parts [(:text ,(minuet--make-chat-llm-shot context minuet-gemini-options))])))))) + :as 'string + :filter (minuet--make-process-stream-filter --response--) + :then + (lambda (json) + (when-let* ((result (minuet--stream-decode json #'minuet--gemini-get-text-fn)) + (completion-items (minuet--parse-completion-itmes-default result)) + (completion-items (minuet--filter-context-sequence-in-items + completion-items + context)) + (completion-items (minuet--remove-spaces completion-items))) + (funcall callback completion-items))) + :else + (lambda (err) + (minuet--handle-chat-completion-timeout + context err --response-- #'minuet--gemini-get-text-fn "Gemini" callback))) + minuet--current-requests))) (defun minuet--setup-auto-suggestion ()