karthink/gptel

Documentation for the API to change LLMs

Closed this issue · 2 comments

Hello Karthik, you asked in the issues, from a user perspective, what a good gptel-ui would look like.
(#249 and related issues)

I thought about this for a bit. One interesting thing i miss, is a very simple "Quickchange Menu" to change the LLM-Model.

Here is a first draft.
screenshot_20240928_074718

#+begin_src elisp
(require 'transient)

(defvar my-model-variable nil "Variable to store the selected model.")

(defun set-my-model-variable (value)
  "Set the my-model-variable to the given VALUE."
  (setq my-model-variable value))

(transient-define-prefix my-select-model-menu ()
  "Transient for selecting AI models."
  ["Select AI Model"
   ("1" "claude opus"   (lambda () (interactive) (set-my-model-variable "claude opus")))
   ("2" "gpt4o"         (lambda () (interactive) (set-my-model-variable "gpt4o")))
   ("3" "claude sonnet" (lambda () (interactive) (set-my-model-variable "claude sonnet")))
   ("4" "gpt4-turbo"    (lambda () (interactive) (set-my-model-variable "gpt4-turbo")))
   ])

(global-set-key (kbd "C-c m") 'my-select-model-menu)
#+end_src

If you put this code in an orgmode file, and press C-c C-c and C-c m the code works, but it is not connected to any function.

What need is info about, how to wire this code to gptel. Of course it should not only set the string to but actually change the model.

is there any existing, documentation on how to do that, or could you provide some help?

I tried to figure it out on my own by looking at
transient-define-prefix gptel-menu () in gptel-transient.el but this code is way above my novice understanding of lisp.

Can you help? Thanks a lot!

See #189, specifically the code block under "Helper functions". Let me know if you need more help.

Perhaps something like this should be added to the wiki.