[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/ellama 7b6a6b0d88 2/2: Make default prompt templates cu
From: |
ELPA Syncer |
Subject: |
[elpa] externals/ellama 7b6a6b0d88 2/2: Make default prompt templates customizable |
Date: |
Sun, 7 Jan 2024 15:57:44 -0500 (EST) |
branch: externals/ellama
commit 7b6a6b0d8893d2f6a7aadf36e8664df4471f1179
Author: Sergey Kostyaev <sskostyaev@gmail.com>
Commit: Sergey Kostyaev <sskostyaev@gmail.com>
Make default prompt templates customizable
Fixes #37
---
NEWS.org | 2 +
README.md | 1 +
ellama.el | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++++---------
3 files changed, 109 insertions(+), 18 deletions(-)
diff --git a/NEWS.org b/NEWS.org
index e69f41d6ea..5da3f2d133 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -1,3 +1,5 @@
+* Version 0.5.2
+- Make default prompt templates customizable.
* Version 0.5.1
- Use more meaningful buffer names.
* Version 0.5.0
diff --git a/README.md b/README.md
index 1088ff8edf..f54641d958 100644
--- a/README.md
+++ b/README.md
@@ -211,6 +211,7 @@ documentation](https://elpa.gnu.org/packages/llm.html)
filling behaviour.
- `ellama-name-prompt-words-count`: Count of words in prompt to
generate name.
+- Prompt templates for every command.
## Acknowledgments
diff --git a/ellama.el b/ellama.el
index f3a2648033..bbcba3045b 100644
--- a/ellama.el
+++ b/ellama.el
@@ -6,7 +6,7 @@
;; URL: http://github.com/s-kostyaev/ellama
;; Keywords: help local tools
;; Package-Requires: ((emacs "28.1") (llm "0.6.0") (spinner "1.7.4"))
-;; Version: 0.5.1
+;; Version: 0.5.2
;; SPDX-License-Identifier: GPL-3.0-or-later
;; Created: 8th Oct 2023
@@ -169,6 +169,91 @@
:group 'ellama
:type 'integer)
+(defcustom ellama-ask-about-prompt-template "Text:\n%s\nRegarding this text,
%s"
+ "Prompt template for `ellama-ask-about'."
+ :group 'ellama
+ :type 'string)
+
+(defcustom ellama-translate-word-prompt-template "Translate %s to %s"
+ "Promp template for `ellama-translate' with single word."
+ :group 'ellama
+ :type 'string)
+
+(defcustom ellama-translate-region-prompt-template "Translate the following
text to %s:\n%s"
+ "Promp template for `ellama-translate' with active region."
+ :group 'ellama
+ :type 'string)
+
+(defcustom ellama-define-word-prompt-template "Define %s"
+ "Prompt template for `ellama-define-word'."
+ :group 'ellama
+ :type 'string)
+
+(defcustom ellama-summarize-prompt-template "Text:\n%s\nSummarize it."
+ "Prompt template for `ellama-summarize'."
+ :group 'ellama
+ :type 'string)
+
+(defcustom ellama-code-review-prompt-template "Review the following code and
make concise suggestions:\n```\n%s\n```"
+ "Prompt template for `ellama-code-review'."
+ :group 'ellama
+ :type 'string)
+
+(defcustom ellama-change-prompt-template "Change the following text, %s, just
output the final text without additional quotes around it:\n%s"
+ "Prompt template for `ellama-change'."
+ :group 'ellama
+ :type 'string)
+
+(defcustom ellama-improve-grammar-prompt-template "improve grammar and
spelling"
+ "Prompt template for `ellama-improve-grammar'."
+ :group 'ellama
+ :type 'string)
+
+(defcustom ellama-improve-wording-prompt-template "use better wording"
+ "Prompt template for `ellama-improve-wording'."
+ :group 'ellama
+ :type 'string)
+
+(defcustom ellama-improve-conciseness-prompt-template "make it as simple and
concise as possible"
+ "Prompt template for `ellama-improve-conciseness'."
+ :group 'ellama
+ :type 'string)
+
+(defcustom ellama-code-edit-prompt-template "Regarding the following code, %s,
only ouput the result code in format ```language\n...\n```:\n```\n%s\n```"
+ "Prompt template for `ellama-code-edit'."
+ :group 'ellama
+ :type 'string)
+
+(defcustom ellama-code-improve-prompt-template "Enhance the following code,
only ouput the result code in format ```language\n...\n```:\n```\n%s\n```"
+ "Prompt template for `ellama-code-improve'."
+ :group 'ellama
+ :type 'string)
+
+(defcustom ellama-code-complete-prompt-template "Continue the following code,
only write new code in format ```language\n...\n```:\n```\n%s\n```"
+ "Prompt template for `ellama-code-complete'."
+ :group 'ellama
+ :type 'string)
+
+(defcustom ellama-code-add-prompt-template "Context: \n```\n%s\n```\nBased on
this context, %s, only ouput the result in format ```\n...\n```"
+ "Prompt template for `ellama-code-add'."
+ :group 'ellama
+ :type 'string)
+
+(defcustom ellama-make-format-prompt-template "Render the following text as a
%s:\n%s"
+ "Prompt template for `ellama-make-format'."
+ :group 'ellama
+ :type 'string)
+
+(defcustom ellama-make-list-prompt-template "markdown list"
+ "Prompt template for `ellama-make-list'."
+ :group 'ellama
+ :type 'string)
+
+(defcustom ellama-make-table-prompt-template "markdown table"
+ "Prompt template for `ellama-make-table'."
+ :group 'ellama
+ :type 'string)
+
(defvar-local ellama--chat-prompt nil)
(defvar-local ellama--change-group nil)
@@ -286,6 +371,7 @@ when the request completes (with BUFFER current)."
(cancel-change-group ellama--change-group)
(spinner-stop)
(funcall errcb msg))))))))
+
(defun ellama-chat-done (_)
"Chat done."
(save-excursion
@@ -318,7 +404,7 @@ when the request completes (with BUFFER current)."
(text (if (region-active-p)
(buffer-substring-no-properties (region-beginning)
(region-end))
(buffer-substring-no-properties (point-min) (point-max)))))
- (ellama-chat (format "Text:\n%s\nRegarding this text, %s" text input))))
+ (ellama-chat (format ellama-ask-about-prompt-template text input))))
;;;###autoload
(defun ellama-ask-selection ()
@@ -364,17 +450,19 @@ when the request completes (with BUFFER current)."
(interactive)
(if (region-active-p)
(ellama-instant
- (format "Translate the following text to %s:\n%s"
+ (format ellama-translate-region-prompt-template
ellama-language
(buffer-substring-no-properties (region-beginning)
(region-end))))
(ellama-instant
- (format "Translate %s to %s" (thing-at-point 'word) ellama-language))))
+ (format ellama-translate-word-prompt-template
+ (thing-at-point 'word) ellama-language))))
;;;###autoload
(defun ellama-define-word ()
"Find definition of current word."
(interactive)
- (ellama-instant (format "Define %s" (thing-at-point 'word))))
+ (ellama-instant (format ellama-define-word-prompt-template
+ (thing-at-point 'word))))
;;;###autoload
(defun ellama-summarize ()
@@ -383,7 +471,7 @@ when the request completes (with BUFFER current)."
(let ((text (if (region-active-p)
(buffer-substring-no-properties (region-beginning)
(region-end))
(buffer-substring-no-properties (point-min) (point-max)))))
- (ellama-instant (format "Text:\n%s\nSummarize it." text))))
+ (ellama-instant (format ellama-summarize-prompt-template text))))
;;;###autoload
(defun ellama-code-review ()
@@ -392,7 +480,7 @@ when the request completes (with BUFFER current)."
(let ((text (if (region-active-p)
(buffer-substring-no-properties (region-beginning)
(region-end))
(buffer-substring-no-properties (point-min) (point-max)))))
- (ellama-instant (format "Review the following code and make concise
suggestions:\n```\n%s\n```" text))))
+ (ellama-instant (format ellama-code-review-prompt-template text))))
;;;###autoload
(defun ellama-change (change)
@@ -408,7 +496,7 @@ when the request completes (with BUFFER current)."
(kill-region beg end)
(ellama-stream
(format
- "Change the following text, %s, just output the final text without
additional quotes around it:\n%s"
+ ellama-change-prompt-template
change text)
:point beg)))
@@ -416,19 +504,19 @@ when the request completes (with BUFFER current)."
(defun ellama-improve-grammar ()
"Enhance the grammar and spelling in the currently selected region or
buffer."
(interactive)
- (ellama-change "improve grammar and spelling"))
+ (ellama-change ellama-improve-grammar-prompt-template))
;;;###autoload
(defun ellama-improve-wording ()
"Enhance the wording in the currently selected region or buffer."
(interactive)
- (ellama-change "use better wording"))
+ (ellama-change ellama-improve-wording-prompt-template))
;;;###autoload
(defun ellama-improve-conciseness ()
"Make the text of the currently selected region or buffer concise and
simple."
(interactive)
- (ellama-change "make it as simple and concise as possible"))
+ (ellama-change ellama-improve-conciseness-prompt-template))
;;;###autoload
(defun ellama-code-edit (change)
@@ -444,7 +532,7 @@ when the request completes (with BUFFER current)."
(kill-region beg end)
(ellama-stream
(format
- "Regarding the following code, %s, only ouput the result code in format
```language\n...\n```:\n```\n%s\n```"
+ ellama-code-edit-prompt-template
change text)
:filter #'ellama--code-filter
:point beg)))
@@ -463,7 +551,7 @@ when the request completes (with BUFFER current)."
(kill-region beg end)
(ellama-stream
(format
- "Enhance the following code, only ouput the result code in format
```language\n...\n```:\n```\n%s\n```"
+ ellama-code-improve-prompt-template
text)
:filter #'ellama--code-filter
:point beg)))
@@ -481,7 +569,7 @@ when the request completes (with BUFFER current)."
(text (buffer-substring-no-properties beg end)))
(ellama-stream
(format
- "Continue the following code, only write new code in format
```language\n...\n```:\n```\n%s\n```"
+ ellama-code-complete-prompt-template
text)
:filter #'ellama--code-filter
:point end)))
@@ -501,7 +589,7 @@ buffer."
(text (buffer-substring-no-properties beg end)))
(ellama-stream
(format
- "Context: \n```\n%s\n```\nBased on this context, %s, only ouput the
result in format ```\n...\n```"
+ ellama-code-add-prompt-template
text description)
:filter #'ellama--code-filter)))
@@ -520,7 +608,7 @@ buffer."
(kill-region beg end)
(ellama-stream
(format
- "Render the following text as a %s:\n%s"
+ ellama-make-format-prompt-template
needed-format text)
:point beg)))
@@ -528,13 +616,13 @@ buffer."
(defun ellama-make-list ()
"Create markdown list from active region or current buffer."
(interactive)
- (ellama-make-format "markdown list"))
+ (ellama-make-format ellama-make-list-prompt-template))
;;;###autoload
(defun ellama-make-table ()
"Create markdown table from active region or current buffer."
(interactive)
- (ellama-make-format "markdown table"))
+ (ellama-make-format ellama-make-table-prompt-template))
(defun ellama-summarize-webpage (url)
"Summarize webpage fetched from URL."