karthink / gptel

A simple LLM client for Emacs
GNU General Public License v3.0
1.06k stars 116 forks source link

Turn `gptel--infix-model` reader into a loop selection with configurable choices. #72

Closed tshu-w closed 1 year ago

tshu-w commented 1 year ago

I often switch gptel-model, but currently the reader of gptel--infix-mode uses completing-read, which requires selecting the model and pressing enter every time. I think it can be changed to cyclic selection and the candidates can be configurable. I can submit a PR, but I would like to know your thoughts.

  (with-eval-after-load 'gptel-transient
    (defvar gptel--models '("gpt-3.5-turbo-0301" "gpt-3.5-turbo" "gpt-4")
      "AI Models for Chat.")
    (transient-define-infix gptel--infix-model ()
      "AI Model for Chat."
      :description "GPT Model: "
      :class 'transient-lisp-variable
      :variable 'gptel-model
      :key "m"
      :choices 'gptel--models
      :reader (lambda (prompt &rest _)
                (nth (% (1+ (cl-position gptel-model gptel--models :test #'equal))
                          (length gptel--models)) gptel--models))))
karthink commented 1 year ago
  1. Cyclic selection is built into transient (I think) as one of the infix classes, you don't need to supply a custom reader.

  2. While there are only three models right now, I'm planning to add support for more in the future (such as many local LLMs and DALL-E), so cyclic selection will become cumbersome then.

My suggestion for now is to use the reader you supplied as a custom function and bind it to a key:

(defun gptel-model-cycle ()
  (interactive)
  (let ((gptel--models '("gpt-3.5-turbo-0301" "gpt-3.5-turbo" "gpt-4")))
    (setq-local gptel-model
                (nth (% (1+ (cl-position gptel-model gptel--models :test #'equal))
                        (length gptel--models))
                     gptel--models))))

I understand the problem though -- let me think for a bit about how the UI can be better.

tshu-w commented 1 year ago
  1. Cyclic selection is built into transient (I think) as one of the infix classes, you don't need to supply a custom reader.

Thank you for mentioning it. I am not very familiar with transient and I found that I cannot make transient switches select to save to gptel-model.

While there are only three models right now, I'm planning to add support for more in the future (such as many local LLMs and DALL-E), so cyclic selection will become cumbersome then.

I understand your concern and I'll close this issue as the user can override gptel--infix-model easily.

tshu-w commented 1 year ago

BTW, I wonder if there is any way to select a directive and quit without press q.