Skip to content

Commit 68e11b1

Browse files
committed
Make model filtering logic more generic
1 parent 752a2b8 commit 68e11b1

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

chatgpt-shell.el

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -521,11 +521,26 @@ 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-ignored-model-versions nil
525-
"The list of model versions to ignore when swapping the model."
526-
:type '(repeat string)
524+
(defcustom chatgpt-shell-model-filter (lambda (_model) t)
525+
"A predicate used to determine which models should be shown in
526+
`chatgpt-shell-swap-model'."
527+
:type 'function
527528
:group 'chatgpt-shell)
528529

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 (model)
535+
(member (map-elt model :version) versions)))
536+
537+
(defun chatgpt-shell-ignore-model-versions (versions)
538+
"A predicate intended for use with `chatgpt-shell-model-filter' to
539+
allow model versions specified in
540+
`chatgpt-shell-ignored-model-versions'."
541+
(lambda (model)
542+
(not (member (map-elt model :version) versions))))
543+
529544
(defun chatgpt-shell-swap-model ()
530545
"Swap model version from `chatgpt-shell-models'."
531546
(interactive)
@@ -544,10 +559,7 @@ Downloaded from https://github.com/f/awesome-chatgpt-prompts."
544559
(format (format "%%-%ds %%s" width)
545560
(map-elt model :provider)
546561
(map-elt model :version)))
547-
(seq-filter (lambda (model)
548-
(not (member (map-elt model :version)
549-
chatgpt-shell-ignored-model-versions)))
550-
chatgpt-shell-models)))
562+
(seq-filter chatgpt-shell-model-filter chatgpt-shell-models)))
551563
(selection (nth 1 (split-string (completing-read "Model version: "
552564
models nil t)))))
553565
(progn

0 commit comments

Comments
 (0)