gptel: Show chosen system message in header-line

* gptel.el (gptel): Show chosen system message in
header-line (#274).  Remove the context indicator `[Send: ...]`,
as this needs to be reworked for the upcoming context-inclusion
features anyway.

* gptel-transient.el (gptel-system-prompt): Autoload
`gptel-system-prompt`, this is required for the gptel header-line.
This commit is contained in:
Karthik Chikmagalur 2024-04-02 19:33:39 -07:00
parent 53ee34653e
commit 53a905dafc
2 changed files with 11 additions and 10 deletions

View file

@ -404,6 +404,7 @@ Also format its value in the Transient menu."
;; instead of returning to the system prompt menu. ;; instead of returning to the system prompt menu.
:transient 'transient--do-exit)))))) :transient 'transient--do-exit))))))
;;;###autoload (autoload 'gptel-system-prompt "gptel-transient" nil t)
(transient-define-prefix gptel-system-prompt () (transient-define-prefix gptel-system-prompt ()
"Set the LLM system message for LLM interactions in this buffer. "Set the LLM system message for LLM interactions in this buffer.

View file

@ -108,6 +108,7 @@
(declare-function markdown-mode "markdown-mode") (declare-function markdown-mode "markdown-mode")
(declare-function gptel-curl-get-response "gptel-curl") (declare-function gptel-curl-get-response "gptel-curl")
(declare-function gptel-menu "gptel-transient") (declare-function gptel-menu "gptel-transient")
(declare-function gptel-system-prompt "gptel-transient")
(declare-function pulse-momentary-highlight-region "pulse") (declare-function pulse-momentary-highlight-region "pulse")
;; Functions used for saving/restoring gptel state in Org buffers ;; Functions used for saving/restoring gptel state in Org buffers
@ -773,21 +774,20 @@ file."
(format "%s" (gptel-backend-name gptel-backend)))) (format "%s" (gptel-backend-name gptel-backend))))
(propertize " Ready" 'face 'success) (propertize " Ready" 'face 'success)
'(:eval '(:eval
(let* ((l1 (length gptel-model)) (let ((system
(num-exchanges (format "[Prompt: %s]"
(if gptel--num-messages-to-send (or (car-safe (rassoc gptel--system-message gptel-directives))
(format "[Send: %s exchanges]" gptel--num-messages-to-send) (truncate-string-to-width gptel--system-message 15 nil nil t)))))
"[Send: buffer]"))
(l2 (length num-exchanges)))
(concat (concat
(propertize (propertize
" " 'display `(space :align-to ,(max 1 (- (window-width) (+ 2 l1 l2))))) " " 'display
`(space :align-to (- right ,(+ 2 (length gptel-model) (length system)))))
(propertize (propertize
(buttonize num-exchanges (buttonize system
(lambda (&rest _) (gptel-menu))) (lambda (&rest _) (gptel-system-prompt)))
'mouse-face 'highlight 'mouse-face 'highlight
'help-echo 'help-echo
"Number of past exchanges to include with each request") "System message for buffer")
" " " "
(propertize (propertize
(buttonize (concat "[" gptel-model "]") (buttonize (concat "[" gptel-model "]")