gptel-transient: Adjust several menu options

* gptel-transient.el (gptel-menu, gptel-system-prompt--setup,
gptel-system-prompt, gptel--infix-temperature,
transient-format-value, gptel--additional-directive,
gptel--suffix-system-message): Tweak to the "additional directive"
overlay display.  `gptel-menu` changes based on feedback
from #249 (thanks to @jwr):

- Keys to set the system message are remapped from "h" to
"s" (mnemonic)
- `gptel--infix-temperature` is now hidden by default and requires
enabling `gptel-expert-commands`
This commit is contained in:
Karthik Chikmagalur 2024-03-15 14:53:35 -07:00
parent 7d19874d4c
commit 65dd461f4d

View file

@ -123,19 +123,19 @@ which see."
gptel--system-message (max (- (window-width) 6) 14) nil nil t))) gptel--system-message (max (- (window-width) 6) 14) nil nil t)))
["" [""
"Instructions" "Instructions"
("h" "Set system message" gptel-system-prompt :transient t) ("s" "Set system message" gptel-system-prompt :transient t)
(gptel--additional-directive :if (lambda () gptel-expert-commands))]] (gptel--additional-directive :if (lambda () gptel-expert-commands))]]
[["Model Parameters" [["Model Parameters"
(gptel--infix-provider) (gptel--infix-provider)
;; (gptel--infix-model) ;; (gptel--infix-model)
(gptel--infix-max-tokens) (gptel--infix-max-tokens)
(gptel--infix-num-messages-to-send) (gptel--infix-num-messages-to-send)
(gptel--infix-temperature)] (gptel--infix-temperature :if (lambda () gptel-expert-commands))]
["Prompt from" ["Prompt from"
("p" "Minibuffer instead" "p") ("p" "Minibuffer instead" "p")
("y" "Kill-ring instead" "y") ("y" "Kill-ring instead" "y")
"" ""
("i" "Replace/Delete prompt" "i")] ("i" "Respond in place" "i")]
["Response to" ["Response to"
("m" "Minibuffer instead" "m") ("m" "Minibuffer instead" "m")
("g" "gptel session" "g" ("g" "gptel session" "g"
@ -214,7 +214,7 @@ which see."
'gptel-system-prompt 'gptel-system-prompt
(cl-loop for (type . prompt) in gptel-directives (cl-loop for (type . prompt) in gptel-directives
;; Avoid clashes with the custom directive key ;; Avoid clashes with the custom directive key
with unused-keys = (delete ?h (number-sequence ?a ?z)) with unused-keys = (delete ?s (number-sequence ?a ?z))
with width = (window-width) with width = (window-width)
for name = (symbol-name type) for name = (symbol-name type)
for key = (seq-find (lambda (k) (member k unused-keys)) name (seq-first unused-keys)) for key = (seq-find (lambda (k) (member k unused-keys)) name (seq-first unused-keys))
@ -268,9 +268,11 @@ More extensive system messages can be useful for specific tasks.
Customize `gptel-directives' for task-specific prompts." Customize `gptel-directives' for task-specific prompts."
[:description [:description
(lambda () (format "Current directive: %s" (lambda () (format "System Message: %s"
(truncate-string-to-width (string-replace
gptel--system-message 100 nil nil t))) "\n" ""
(truncate-string-to-width
gptel--system-message 100 nil nil t))))
:class transient-column :class transient-column
:setup-children gptel-system-prompt--setup :setup-children gptel-system-prompt--setup
:pad-keys t]) :pad-keys t])
@ -411,11 +413,11 @@ responses."
(transient-define-infix gptel--infix-temperature () (transient-define-infix gptel--infix-temperature ()
"Temperature of request." "Temperature of request."
:description "Randomness (0 - 2.0)" :description "Temperature (0 - 2.0)"
:class 'transient-lisp-variable :class 'transient-lisp-variable
:variable 'gptel-temperature :variable 'gptel-temperature
:key "-t" :key "-t"
:prompt "Set temperature (0.0-2.0, leave empty for default): " :prompt "Temperature controls the response randomness (0.0-2.0, leave empty for default): "
:reader 'gptel--transient-read-variable) :reader 'gptel--transient-read-variable)
;; ** Infix for the refactor/rewrite system message ;; ** Infix for the refactor/rewrite system message
@ -456,7 +458,8 @@ Also format its value in the Transient menu."
(ov (oref obj overlay)) (ov (oref obj overlay))
(argument (oref obj argument))) (argument (oref obj argument)))
;; Making an overlay ;; Making an overlay
(when (and value (not (string-empty-p value))) (if (or (not value) (string-empty-p value))
(when ov (delete-overlay ov))
(oset obj overlay (gptel--instructions-make-overlay value ov)) (oset obj overlay (gptel--instructions-make-overlay value ov))
(letrec ((ov-clear-hook (letrec ((ov-clear-hook
(lambda () (when-let* ((ov (oref obj overlay)) (lambda () (when-let* ((ov (oref obj overlay))
@ -467,7 +470,7 @@ Also format its value in the Transient menu."
(add-hook 'transient-exit-hook ov-clear-hook))) (add-hook 'transient-exit-hook ov-clear-hook)))
;; Updating transient menu display ;; Updating transient menu display
(if value (if value
(propertize (concat argument (truncate-string-to-width value 15 nil nil "...")) (propertize (concat argument (truncate-string-to-width value 25 nil nil "..."))
'face 'transient-value) 'face 'transient-value)
(propertize (propertize
(concat "(" (symbol-name (oref obj display-nil)) ")") (concat "(" (symbol-name (oref obj display-nil)) ")")
@ -500,7 +503,7 @@ Or in an extended conversation:
:format " %k %d %v" :format " %k %d %v"
:key "d" :key "d"
:argument ":" :argument ":"
:description "Additional directive" :description "Add directive"
:transient t) :transient t)
(defun gptel--additional-directive-get (args) (defun gptel--additional-directive-get (args)
@ -736,7 +739,7 @@ This uses the prompts in the variable
"Edit LLM directives." "Edit LLM directives."
:transient 'transient--do-exit :transient 'transient--do-exit
:description "Set custom directives" :description "Set custom directives"
:key "h" :key "s"
(interactive) (interactive)
(let ((orig-buf (current-buffer)) (let ((orig-buf (current-buffer))
(msg-start (make-marker))) (msg-start (make-marker)))