branch: elpa/gptel commit 040649d598e902af8d22398cdb216fa1d642db01 Author: Karthik Chikmagalur <karthikchikmaga...@gmail.com> Commit: Karthik Chikmagalur <karthikchikmaga...@gmail.com>
gptel: Add command to save a preset * gptel.el (gptel--save-preset): Add a command to save gptel's current settings as a preset. In addition to registering a preset, lisp code to do the same is copied to the kill-ring. This is for the benefit of users who might want to record it in their configurations. The new preset covers a few common gptel settings and does not attempt to cover everything. --- gptel.el | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/gptel.el b/gptel.el index 5f3938c5ee..a47e8d056d 100644 --- a/gptel.el +++ b/gptel.el @@ -3335,6 +3335,38 @@ See gptel's customization options for all available settings." "Get the gptel preset spec with NAME." (alist-get name gptel--known-presets nil nil #'equal)) +(defun gptel--save-preset (name &optional description) + "Save gptel's current settings as a preset with NAME. + +NAME must be a symbol. DESCRIPTION is added if provided. In addition +to registering the preset, elisp code to do the same is copied to the +kill-ring." + (interactive + (list (intern (completing-read "Save gptel settings to (existing or new) preset: " + gptel--known-presets)) + (read-string "Description (optional): "))) + (let ((preset-code + `(gptel-make-preset ',name + :description ,(when (and description + (not (string-blank-p description))) + description) + :backend ,(gptel-backend-name gptel-backend) + :model ',gptel-model + :system ,(if-let* ((directive (car-safe (rassoc gptel--system-message + gptel-directives)))) + `',directive + gptel--system-message) + :tools ,(mapcar #'gptel-tool-name gptel-tools) + :stream ,gptel-stream + :temperature ,gptel-temperature + :max-tokens ,gptel-max-tokens + :use-context ',gptel-use-context + :include-reasoning ,gptel-include-reasoning))) + (kill-new (pp-to-string preset-code)) + (eval preset-code) + (message "Preset %s saved. (Lisp expression for preset saved to kill-ring)" + (propertize (symbol-name name) 'face 'highlight)))) + (defun gptel--apply-preset (preset &optional setter) "Apply gptel PRESET with SETTER.