emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/ellama a0acd24abb 51/53: Add ellama complete command.


From: ELPA Syncer
Subject: [elpa] externals/ellama a0acd24abb 51/53: Add ellama complete command.
Date: Sun, 17 Dec 2023 18:58:00 -0500 (EST)

branch: externals/ellama
commit a0acd24abb2c80104bd51ae76bb4181393551bb8
Author: Sergey Kostyaev <kostyaev.sergey2@wb.ru>
Commit: Sergey Kostyaev <kostyaev.sergey2@wb.ru>

    Add ellama complete command.
---
 README.md | 13 +++++++----
 ellama.el | 79 +++++++++++++++++++++++++++++++++++++--------------------------
 2 files changed, 56 insertions(+), 36 deletions(-)

diff --git a/README.md b/README.md
index caea1e1782..c205fea184 100644
--- a/README.md
+++ b/README.md
@@ -12,15 +12,16 @@ output, making it effortless to use with your preferred 
text editor.
 
 ## What's new
 
+- `10.12.2023` - Added command `ellama-complete`.
+- `17.11.2023` - Changes by ellama is now atomic. It can be useful if
+  you want to undo this changes. Two new commands added:
+  `ellama-ask-selection` and `ellama-ask-line`. Some cosmetic changes
+  done.
 - `28.10.2023` - Switched from
 [ollama](https://github.com/jmorganca/ollama)'s API to [llm
 library](https://elpa.gnu.org/packages/llm.html). [Many
 providers](https://github.com/ahyatt/llm#setting-up-providers)
 supported.
-- `17.11.2023` - Changes by ellama is now atomic. It can be useful if
-  you want to undo this changes. Two new commands added:
-  `ellama-ask-selection` and `ellama-ask-line`. Some cosmetic changes
-  done.
 
 ## Installation
 
@@ -70,6 +71,10 @@ Send selected region or current buffer to ellama chat.
 
 Send current line to ellama chat.
 
+### ellama-complete
+
+Complete text in current buffer with ellama.
+
 ### ellama-translate
 
 Ask Ellama to translate a selected region or word at the point.
diff --git a/ellama.el b/ellama.el
index 96c46cbebc..4f575f3c1a 100644
--- a/ellama.el
+++ b/ellama.el
@@ -113,36 +113,37 @@ in.  Default value is (current-buffer).
                    (with-current-buffer buffer (point)))))
     (with-current-buffer buffer
       (unwind-protect
-       (save-excursion
-       (let* ((start (make-marker))
-              (end (make-marker))
-              (insert-text
-               (lambda (text)
-                 ;; Erase and insert the new text between the marker cons.
-                 (with-current-buffer (marker-buffer start)
-                   (save-excursion
-                     (goto-char start)
-                     (delete-region start end)
-                     (insert text))))))
-         (setq ellama--change-group (prepare-change-group))
-         (activate-change-group ellama--change-group)
-          (set-marker start point)
-          (set-marker end point)
-          (set-marker-insertion-type start nil)
-          (set-marker-insertion-type end t)
-         (spinner-start ellama-spinner-type)
-         (llm-chat-streaming ellama-provider
-                             (llm-make-simple-chat-prompt prompt)
-                             insert-text
-                             (lambda (text)
-                               (funcall insert-text text)
-                               (with-current-buffer buffer
-                                 (undo-amalgamate-change-group 
ellama--change-group)
-                                 (accept-change-group ellama--change-group)
-                                 (spinner-stop)))
-                             (lambda (_ msg)
-                               (error "Error calling the LLM: %s" msg)
-                               (cancel-change-group 
ellama--change-group)))))))))
+         (save-excursion
+           (let* ((start (make-marker))
+                  (end (make-marker))
+                  (insert-text
+                   (lambda (text)
+                     ;; Erase and insert the new text between the marker cons.
+                     (with-current-buffer (marker-buffer start)
+                       (save-excursion
+                         (goto-char start)
+                         (delete-region start end)
+                         (insert text)
+                         (fill-region start (point)))))))
+             (setq ellama--change-group (prepare-change-group))
+             (activate-change-group ellama--change-group)
+              (set-marker start point)
+              (set-marker end point)
+              (set-marker-insertion-type start nil)
+              (set-marker-insertion-type end t)
+             (spinner-start ellama-spinner-type)
+             (llm-chat-streaming ellama-provider
+                                 (llm-make-simple-chat-prompt prompt)
+                                 insert-text
+                                 (lambda (text)
+                                   (funcall insert-text text)
+                                   (with-current-buffer buffer
+                                     (undo-amalgamate-change-group 
ellama--change-group)
+                                     (accept-change-group ellama--change-group)
+                                     (spinner-stop)))
+                                 (lambda (_ msg)
+                                   (error "Error calling the LLM: %s" msg)
+                                   (cancel-change-group 
ellama--change-group)))))))))
 
 (defun ellama-stream-filter (prompt prefix suffix buffer point)
   "Query ellama for PROMPT with filtering.
@@ -210,7 +211,8 @@ In BUFFER at POINT will be inserted result between PREFIX 
and SUFFIX."
                  (save-excursion
                    (goto-char start)
                    (delete-region start end)
-                   (insert text))))))
+                   (insert text)
+                   (fill-region start (point)))))))
        (setq ellama--change-group (prepare-change-group))
        (activate-change-group ellama--change-group)
         (set-marker start point)
@@ -256,6 +258,19 @@ In BUFFER at POINT will be inserted result between PREFIX 
and SUFFIX."
                (buffer-substring-no-properties (point-min) (point-max)))))
     (ellama-chat text)))
 
+;;;###autoload
+(defun ellama-complete ()
+  "Complete text in current buffer."
+  (interactive)
+  (let* ((beg (if (region-active-p)
+                 (region-beginning)
+               (point-min)))
+        (end (if (region-active-p)
+                 (region-end)
+               (point)))
+        (text (buffer-substring-no-properties beg end)))
+    (ellama-stream text)))
+
 ;;;###autoload
 (defun ellama-ask-line ()
   "Send current line to ellama chat."
@@ -385,7 +400,7 @@ In BUFFER at POINT will be inserted result between PREFIX 
and SUFFIX."
 
 ;;;###autoload
 (defun ellama-complete-code ()
-  "Change selected code or code in current buffer according to provided 
CHANGE."
+  "Complete selected code or code in current buffer."
   (interactive)
   (let* ((beg (if (region-active-p)
                  (region-beginning)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]