Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to bind changing a model to a key for quicker access? #680

Closed
benma opened this issue Mar 4, 2025 · 2 comments
Closed

How to bind changing a model to a key for quicker access? #680

benma opened this issue Mar 4, 2025 · 2 comments
Labels
question Further information is requested

Comments

@benma
Copy link

benma commented Mar 4, 2025

To change the model, currently I invoke gptel-menu, then hit -m. I change models frequently, so I'd like have a simple keybinding to launch into this directly. Is there a way?

Thanks

@benma benma added the question Further information is requested label Mar 4, 2025
@wlauppe
Copy link

wlauppe commented Mar 4, 2025

Hello @benma you can use this helper function

(defun set-gptel-model-and-backend (model backend)
  "Set the gptel-model and gptel-backend variables based on the selected MODEL and BACKEND."
  (setq gptel-model model)
  (setq gptel-backend (cdr (assoc backend gptel--known-backends)))
  (message "\"%s:%s\" selected" backend model))

then you can change the model with instructions like this:

(set-gptel-model-and-backend 'gpt-4-turbo "ChatGPT")
(set-gptel-model-and-backend 'claude-3-opus-20240229 "Claude")

you can read the model and backend names from gptel-menu and adapt the lines accordingly

I have additionally defined a "model picker" quick selection menu. If i press "Super-M" the following menu pops up and i can quickly select the needed model by pressing the number.

Image

The full Code in my .emacs file looks like this.

;; gptel model selector
(require 'transient)

(defun set-gptel-model-and-backend (model backend)
  "Set the gptel-model and gptel-backend variables based on the selected MODEL and BACKEND."
  (setq gptel-model model)
  (setq gptel-backend (cdr (assoc backend gptel--known-backends)))
  (message "\"%s:%s\" selected" backend model))

(transient-define-prefix gptel-model-picker ()
  "Transient for selecting AI models."
  ["Select AI Model"
   ("1" "claude opus"   (lambda () (interactive) (set-gptel-model-and-backend 'claude-3-opus-20240229 "Claude")))
   ("2" "gpt4-turbo"    (lambda () (interactive) (set-gptel-model-and-backend 'gpt-4-turbo "ChatGPT")))
   ("3" "gpt4o"         (lambda () (interactive) (set-gptel-model-and-backend 'gpt-4o "Github Models 2")))
   ("4" "claude sonnet" (lambda () (interactive) (set-gptel-model-and-backend 'claude-3-5-sonnet-20240620 "Claude")))
   ("5" "new claude sonnet" (lambda () (interactive) (set-gptel-model-and-backend 'claude-3-5-sonnet-20241022 "Claude")))
   ("6" "claude sonnet 3.7" (lambda () (interactive) (set-gptel-model-and-backend 'claude-3-7-sonnet-20250219 "Claude")))
   ("7" "Deepseek-R1" (lambda () (interactive) (set-gptel-model-and-backend' DeepSeek-R1 "Github Models 2" )))
   ("b" "Deepseek-R1 backup " (lambda () (interactive) (set-gptel-model-and-backend' DeepSeek-R1 "Github Models" )))
   ("c" "Deepseek-R1 deepseek api " (lambda () (interactive) (set-gptel-model-and-backend' deepseek-reasoner "DeepSeek" )))
   ("8" "Deepseek-V3" (lambda () (interactive) (set-gptel-model-and-backend 'deepseek/deepseek-chat "OpenRouter")))
   ])

(global-set-key (kbd "C-c m") 'gptel-model-picker)
(global-set-key (kbd "s-m") 'gptel-model-picker)

does this answer your question or do you need further help?

@benma
Copy link
Author

benma commented Mar 4, 2025

This works very nicely, thanks a lot.

@benma benma closed this as completed Mar 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants