Skip to content

Commit 08e2f68

Browse files
authored
Merge pull request #316 from djr7C4/ignored-models
Add the ability to ignore some model versions when swapping
2 parents 7144f5e + 53dbd46 commit 08e2f68

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

chatgpt-shell.el

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,30 @@ Downloaded from https://github.com/f/awesome-chatgpt-prompts."
521521
(setq chatgpt-shell-models (chatgpt-shell--make-default-models))
522522
(message "Reloaded %d models" (length chatgpt-shell-models)))
523523

524+
(defcustom chatgpt-shell-model-filter nil
525+
"A function that is applied `chatgpt-shell-models' to determine
526+
which models should be shown in `chatgpt-shell-swap-model'."
527+
:type 'function
528+
:group 'chatgpt-shell)
529+
530+
(defun chatgpt-shell-allow-model-versions (versions)
531+
"Return a predicate that accepts models only if their version
532+
appears in versions. This is intended for use with
533+
`chatgpt-shell-model-filter'."
534+
(lambda (models)
535+
(seq-filter (lambda (model)
536+
(member (map-elt model :version) versions))
537+
models)))
538+
539+
(defun chatgpt-shell-ignore-model-versions (versions)
540+
"A predicate intended for use with `chatgpt-shell-model-filter' to
541+
allow model versions specified in
542+
`chatgpt-shell-ignored-model-versions'."
543+
(lambda (models)
544+
(seq-filter (lambda (model)
545+
(not (member (map-elt model :version) versions)))
546+
models)))
547+
524548
(defun chatgpt-shell-swap-model ()
525549
"Swap model version from `chatgpt-shell-models'."
526550
(interactive)
@@ -539,7 +563,9 @@ Downloaded from https://github.com/f/awesome-chatgpt-prompts."
539563
(format (format "%%-%ds %%s" width)
540564
(map-elt model :provider)
541565
(map-elt model :version)))
542-
chatgpt-shell-models))
566+
(if chatgpt-shell-model-filter
567+
(funcall chatgpt-shell-model-filter chatgpt-shell-models)
568+
chatgpt-shell-models)))
543569
(selection (nth 1 (split-string (completing-read "Model version: "
544570
models nil t)))))
545571
(progn

0 commit comments

Comments
 (0)