branch: externals/ellama
commit e15c0aa7db4f7cbb778c2ca086f24d66d0ee8ebe
Author: Sergey Kostyaev <sskosty...@gmail.com>
Commit: Sergey Kostyaev <sskosty...@gmail.com>

    Add `ellama-write` command
    
    Added a new command `ellama-write` that allows users to generate text
    based on an instruction and the current context. The command prompts
    for an instruction and, if a region is active, adds the selected text
    to the context before generating the response. Updated keybindings and
    documentation accordingly.
---
 README.org |  8 ++++++++
 ellama.el  | 21 +++++++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/README.org b/README.org
index f4c0ab7a64..8fa8a8ffc5 100644
--- a/README.org
+++ b/README.org
@@ -108,6 +108,13 @@ buffer and continue conversation. If called with universal 
argument
 (~C-u~) will start new session with llm model interactive selection.
 [[imgs/ellama-ask.gif]]
 
+*** ellama-write
+
+This command allows you to generate text using an LLM. When called
+interactively, it prompts for an instruction that is then used to
+generate text based on the context. If a region is active, the
+selected text is added to the context before generating the response.
+
 *** ellama-chat-send-last-message
 
 Send last user message extracted from current ellama chat buffer.
@@ -288,6 +295,7 @@ Ellama, using the ~ellama-keymap-prefix~ prefix (not set by 
default):
 
 | Keymap | Function                        | Description                  |
 |--------+---------------------------------+------------------------------|
+| "w"    | ellama-write                    | Write                        |
 | "c c"  | ellama-code-complete            | Code complete                |
 | "c a"  | ellama-code-add                 | Code add                     |
 | "c e"  | ellama-code-edit                | Code edit                    |
diff --git a/ellama.el b/ellama.el
index 519c432526..49726ff0df 100644
--- a/ellama.el
+++ b/ellama.el
@@ -145,6 +145,7 @@
     (define-key map (kbd "a l") 'ellama-ask-line)
     (define-key map (kbd "a s") 'ellama-ask-selection)
     ;; text
+    (define-key map (kbd "w") 'ellama-write)
     (define-key map (kbd "t t") 'ellama-translate)
     (define-key map (kbd "t b") 'ellama-translate-buffer)
     (define-key map (kbd "t c") 'ellama-complete)
@@ -259,6 +260,16 @@ You are a summarizer. You write a summary of the input 
**IN THE SAME LANGUAGE AS
   :group 'ellama
   :type 'string)
 
+(defcustom ellama-write-prompt-template "<SYSTEM>
+Write text, based on provided context and instruction. Do not add any 
explanation or acknowledgement, just follow instruction.
+</SYSTEM>
+<INSTRUCTION>
+%s
+</INSTRUCTION>"
+  "Prompt template for `ellama-write'."
+  :group 'ellama
+  :type 'string)
+
 (defcustom ellama-improve-grammar-prompt-template "improve grammar and 
spelling"
   "Prompt template for `ellama-improve-grammar'."
   :group 'ellama
@@ -2193,6 +2204,15 @@ ARGS contains keys for fine control.
     (ellama-context-add-buffer (current-buffer)))
   (ellama-chat ellama-code-review-prompt-template nil :provider 
ellama-coding-provider))
 
+;;;###autoload
+(defun ellama-write (instruction)
+  "Write text based on context and INSTRUCTION at point."
+  (interactive "sInstruction: ")
+  (when (region-active-p)
+    (ellama-context-add-selection))
+  (ellama-stream (format ellama-write-prompt-template instruction)
+                :point (point)))
+
 ;;;###autoload
 (defun ellama-change (change &optional edit-template)
   "Change selected text or text in current buffer according to provided CHANGE.
@@ -2563,6 +2583,7 @@ Call CALLBACK on result list of strings.  ARGS contains 
keys for fine control.
   "Main Menu."
   [["Main"
     ("c" "Chat" ellama-chat)
+    ("w" "Write" ellama-write)
     ("P" "Proofread" ellama-proofread)
     ("a" "Ask Commands" ellama-transient-ask-menu)
     ("C" "Code Commands" ellama-transient-code-menu)]]

Reply via email to