Skip to content

Commit 1a3ccdf

Browse files
committed
gptel: Support prefixing dynamic system messages with lambda
* gptel.el (gptel--parse-directive): Add optional `prefix-lambda` argument to prepend a lambda symbol (λ) and the first line of the documentation string, if present, to the system message. * gptel-prefix.el (gptel--infix-add-directive): Call `gptel--parse-directive' with the new `prefix-lambda' arg.
1 parent b2e5404 commit 1a3ccdf

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

gptel-transient.el

+1-1
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,7 @@ Or in an extended conversation:
10801080
gptel--read-with-prefix-help)
10811081
:reader (lambda (prompt initial history)
10821082
(let* ((directive
1083-
(car-safe (gptel--parse-directive gptel--system-message 'raw)))
1083+
(car-safe (gptel--parse-directive gptel--system-message 'raw t)))
10841084
(cycle-prefix (lambda () (interactive)
10851085
(gptel--read-with-prefix directive)))
10861086
(minibuffer-local-map

gptel.el

+13-3
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,7 @@ replaced with REPLACEMENT."
10721072
from-template width)))
10731073
(t "")))
10741074

1075-
(defun gptel--parse-directive (directive &optional raw)
1075+
(defun gptel--parse-directive (directive &optional raw lambda-prefix)
10761076
"Parse DIRECTIVE into a backend-appropriate form.
10771077
10781078
DIRECTIVE is a gptel directive: it can be a string, a list or a
@@ -1083,11 +1083,21 @@ and a template consisting of alternating user/LLM
10831083
records (a list of strings or nil).
10841084
10851085
If RAW is non-nil, the user/LLM records are not processed and are
1086-
returned as a list of strings."
1086+
returned as a list of strings.
1087+
1088+
If LAMBDA-PREFIX is non-nil, prefix dynamic system message with a
1089+
lambda sign (λ) and the documentation string, if any."
10871090
(and directive
10881091
(cl-etypecase directive
10891092
(string (list directive))
1090-
(function (gptel--parse-directive (funcall directive) raw))
1093+
(function (let ((x (gptel--parse-directive (funcall directive) raw)))
1094+
(if lambda-prefix
1095+
(cons (concat ""
1096+
(and-let* ((doc (documentation directive)))
1097+
(concat ": " (substring doc nil
1098+
(string-match-p "\n" doc))))
1099+
"] " (car-safe x)) (cdr x))
1100+
x)))
10911101
(cons (if raw directive
10921102
(cons (car directive)
10931103
(gptel--parse-list

0 commit comments

Comments
 (0)