[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/gptel 5ebaf361f1 046/273: gptel: Handle the prompt prefix
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/gptel 5ebaf361f1 046/273: gptel: Handle the prompt prefix string automatically |
Date: |
Wed, 1 May 2024 10:01:35 -0400 (EDT) |
branch: elpa/gptel
commit 5ebaf361f1d96801f913943ce6d57f703abfb594
Author: Karthik Chikmagalur <karthikchikmagalur@gmail.com>
Commit: Karthik Chikmagalur <karthikchikmagalur@gmail.com>
gptel: Handle the prompt prefix string automatically
* gptel.el (gptel-prompt-prefix-alist, gptel--playback, gptel,
gptel--insert-response, gptel-prompt-string): The prompt prefix
string is chosen automatically from the new variable
`gptel-prompt-prefix-alist', which maps major modes to the prefix
string to insert.
---
gptel.el | 22 ++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)
diff --git a/gptel.el b/gptel.el
index 7feaca5c7f..0e58997a81 100644
--- a/gptel.el
+++ b/gptel.el
@@ -108,7 +108,18 @@ return the transformed string."
(defvar gptel-default-mode (if (featurep 'markdown-mode)
'markdown-mode
'text-mode))
-(defvar gptel-prompt-string "### ")
+
+;; TODO: Handle `prog-mode' using the `comment-start' variable
+(defcustom gptel-prompt-prefix-alist
+ '((markdown-mode . "### ")
+ (org-mode . "*** ")
+ (text-mode . "### "))
+ "String inserted after the response from ChatGPT.
+
+This is an alist mapping major modes to the prefix strings. This
+is only inserted in dedicated gptel buffers."
+ :group 'gptel
+ :type '(alist :key-type symbol :value-type string))
;; Model and interaction parameters
(defvar-local gptel--system-message
@@ -153,6 +164,9 @@ By default, \"openai.com\" is used as HOST and \"apikey\"
as USER."
"Ensure VAL is a number."
(if (stringp val) (string-to-number val) val))
+(defun gptel-prompt-string ()
+ (or (alist-get major-mode gptel-prompt-prefix-alist) ""))
+
(defvar-local gptel--old-header-line nil)
(define-minor-mode gptel-mode
"Minor mode for interacting with ChatGPT."
@@ -222,7 +236,7 @@ See `gptel--url-get-response' for details."
(insert content-str)
(pulse-momentary-highlight-region p (point)))
(when gptel-mode
- (insert "\n\n" gptel-prompt-string)
+ (insert "\n\n" (gptel-prompt-string))
(gptel--update-header-line " Ready" 'success))))
(goto-char (- (point) 2)))
(gptel--update-header-line
@@ -398,7 +412,7 @@ buffer created or switched to."
(visual-line-mode 1))
(t (funcall gptel-default-mode)))
(unless gptel-mode (gptel-mode 1))
- (if (bobp) (insert (or initial gptel-prompt-string)))
+ (if (bobp) (insert (or initial (gptel-prompt-string))))
(pop-to-buffer (current-buffer))
(goto-char (point-max))
(skip-chars-backward "\t\r\n")
@@ -471,7 +485,7 @@ Begin at START-PT."
(min content-length (+ idx 16))))
(setq idx (+ idx 16)))
(when gptel-mode
- (insert "\n\n" gptel-prompt-string)
+ (insert "\n\n" (gptel-prompt-string))
(gptel--update-header-line " Ready" 'success))
(when start-pt (goto-char (marker-position start-pt)))
(accept-change-group (symbol-value handle))
- [nongnu] elpa/gptel 3d6147830e 220/273: gptel: Fix model/backend mismatch (#242), (continued)
- [nongnu] elpa/gptel 3d6147830e 220/273: gptel: Fix model/backend mismatch (#242), ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 07992f79cc 227/273: gptel-anthropic: Support for the Claude haiku model, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel fbb0ee29c4 224/273: gptel-org-test: Add mores tests for org conversion, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 376fb4b423 234/273: gptel-transient: Additional directives option (#249), ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 34a52aa047 246/273: gptel-anthropic: Remove debug code, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel e3b3591d73 240/273: README: Add support for Groq (#257), ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 81bb467104 250/273: gptel: Set window when running post-response hook, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel b4088e3f7b 261/273: README: New pacakge based on gptel, magit-gptcommit (#281), ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 9b094b8b1e 265/273: gptel: Fix url-retrieve response parser bug, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 2b2dbe2664 043/273: gptel: Fix parsing error in url-retrieve buffer, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 5ebaf361f1 046/273: gptel: Handle the prompt prefix string automatically,
ELPA Syncer <=
- [nongnu] elpa/gptel c6abda6f0f 075/273: gptel-transient: Rename gptel-send-menu -> gptel-menu, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 8a9ae56e77 074/273: gptel: Add streaming, in-place options to gptel-request, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel ba133267ec 063/273: gptel: Run post-response-hook after inserting response, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 23caab41cf 042/273: Add gpt-4 model, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 1c07a94e18 052/273: README: Update manual install instructions, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel f0953d569e 069/273: gptel: Simplify response API, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 6c47c0a483 066/273: README: Add videos with streaming, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel c11e53061c 078/273: gptel-transient: New gptel-menu transient options, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 422eba8048 087/273: gptel-curl: Run post-response-hook in gptel buffer, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 42132d3662 093/273: README: tweak description of package, ELPA Syncer, 2024/05/01