Skip to content

Commit 68fbaed

Browse files
authored
Merge pull request #321 from DinoChiesa/custom-read-for-swap
feat: optional custom selector when swapping models
2 parents 0b8f952 + 4f48694 commit 68fbaed

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

chatgpt-shell.el

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,21 @@ See `chatgpt-shell-allow-model-versions' and
529529
:type 'function
530530
:group 'chatgpt-shell)
531531

532+
(defcustom chatgpt-shell-swap-model-selector nil
533+
"Custom function to select a model during swap.
534+
535+
This would allow a user to sort, group, filter, present a different selection
536+
user experience, attach affixations, and so on. An example:
537+
538+
(setq chatgpt-shell-swap-model-selector
539+
(lambda (candidates)
540+
(completing-read \"New model: \"
541+
(my-custom-model-completion-table candidates) nil t)))
542+
543+
See also `chatgpt-shell-swap-model'."
544+
:type 'function
545+
:group 'chatgpt-shell)
546+
532547
(defun chatgpt-shell-allow-model-versions (versions)
533548
"Return a filter function to keep known model VERSIONS only.
534549
@@ -548,7 +563,10 @@ Use with `chatgpt-shell-model-filter'."
548563
models)))
549564

550565
(defun chatgpt-shell-swap-model ()
551-
"Swap model version from `chatgpt-shell-models'."
566+
"Swap model version from `chatgpt-shell-models'.
567+
568+
To select a model, it uses `chatgpt-shell-swap-model-selector' if
569+
non-nil; otherwise `completing-read'."
552570
(interactive)
553571
(if-let* ((last-label (chatgpt-shell--model-label))
554572
(width (let ((width))
@@ -568,8 +586,10 @@ Use with `chatgpt-shell-model-filter'."
568586
(if chatgpt-shell-model-filter
569587
(funcall chatgpt-shell-model-filter chatgpt-shell-models)
570588
chatgpt-shell-models)))
571-
(selection (nth 1 (split-string (completing-read "Model version: "
572-
models nil t)))))
589+
(selection (nth 1 (split-string (if chatgpt-shell-swap-model-selector
590+
(funcall chatgpt-shell-swap-model-selector models)
591+
(completing-read "Model version: "
592+
models nil t))))))
573593
(progn
574594
(when (derived-mode-p 'chatgpt-shell-mode)
575595
(setq-local chatgpt-shell-model-version selection)

0 commit comments

Comments
 (0)