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

Instructions for adding to the list of Gemini models #529

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jlcheng
Copy link
Contributor

@jlcheng jlcheng commented Dec 30, 2024

No description provided.

@karthink
Copy link
Owner

karthink commented Dec 30, 2024

Thanks for the PR!

The model metadata specification method you've used is incorrect, as you need to provide my-gemini-models to gptel-make-gemini. gptel--gemini-models is also an internal variable right now. A simpler way, with an already defined Gemini backend, would be:

(setf (gptel-backend-models gptel-backend)
      (append
       (gptel--process-models '((gemini-2.0-flash-thinking-exp
                                 :context-window 32
                                 ...)))
       (gptel-backend-models gptel-backend)))

where the active gptel-backend is of type Gemini.

As you can see, this method is also quite complicated, and requires the use of an internal function gptel--process-models.


The simplest way to do this is to just push a model onto the model list. i.e. you can do this:

(push 'gemini-2.0-flash-thinking-exp (gptel-backend-models gptel-backend))

where the active gptel-backend is of type Gemini. (Replace gptel-backend with a handle to the Gemini backend instead.)

This works for all backends, so can we turn this PR into a generic section of the README that doesn't pertain to any backend? Here's what I'm picturing:

**** Adding models to gptel backends

While gptel tries to keep up with new models for the major LLM API providers,
you don't have to wait.  You can add compatiable models to any gptel backend in
the following way:

- Find the name of the model you want to add.  In this example we will add
  =gemini-2.0-flash-thinking-exp= to a Gemini backend.
- Obtain a reference to the backend.  If the backend is currently active, this
  is just =gptel-backend=.
- Push a model onto the backend's list of models with
  #+begin_src emacs-lisp
  (push 'gemini-2.0-flash-thinking-exp (gptel-backend-models gptel-backend))
  #+end_src

*Optional*:

You can specify model metadata and capabilities (like vision or tool-use) as
properties of the model symbol:

#+begin_src emacs-lisp
(put 'gemini-2.0-flash-thinking-exp :capabilities '(media tool-use))
(put 'gemini-2.0-flash-thinking-exp :description
"Thinking Mode is capable of stronger reasoning capabilities.")
(put 'gemini-2.0-flash-thinking-exp :context-window 32)
#+end_src

See =gptel-make-gemini= (or equivalent) for recognized metadata fields.

In addition to this section, we can add an FAQ entry that links to it.

@jlcheng
Copy link
Contributor Author

jlcheng commented Jan 3, 2025

The model metadata specification method you've used is incorrect, as you need to provide my-gemini-models to gptel-make-gemini.

Good catch! So dumb of me to miss that. In trying to remove my API key, I overlooked passing my-gemini-models to gptel-make-gemini.

I got an error when I initially tried these instructions. I added this to my init.el file. Can you spot my bug?

(require 'gptel)
(gptel-make-gemini "Gemini" :key my-gemini-api-key :stream t)
;; Here I assumed `gptel-backend` will magically work
(push 'gemini-2.0-flash-thinking-exp (gptel-backend-models gptel-backend))

This however, worked.

(require 'gptel)
(gptel-make-gemini "Gemini" :key my-gemini-api-key :stream t)
(push 'gemini-2.0-flash-thinking-exp (gptel-backend-models (cdr (assoc "Gemini" gptel--known-backends))))

So maybe we change the part about "Obtain a reference to the backend..."? I updated the PR with your suggestions and this modification:

- Push a model onto the backend's list of models with
  #+begin_src emacs-lisp
  (defvar my-gemini-backend (gptel-make-gemini "Gemini"
                              :key my-gemini-api-key :stream t)
    "Reference to the Gemini gptel Backend")
  (push 'gemini-2.0-flash-thinking-exp
        (gptel-backend-models my-gemini-backend))
  #+end_src

LMK what you think

@karthink
Copy link
Owner

Thanks for the update. I think gptel needs a better way to update backend attributes (like the model). The process of obtaining a reference to the backend is going to confuse users. Let me think about this some more. If you have any ideas for how this can be made more user-friendly, let me know.

@karthink
Copy link
Owner

karthink commented Jan 25, 2025

@jlcheng I've added a helper, gptel-get-backend, that should make this process easier. You can use it to get the backend by name:

(gptel-get-backend "Gemini")            ;Returns the Gemini backend

So you can add to its models like this:

(push 'gemini-2.0-flash-thinking-exp
      (gptel-backend-models (gptel-get-backend "Gemini")))

or modify other attributes:

(setf (gptel-backend-host (gptel-get-backend "Gemini")) ...)

I think the instructions in this PR can be made simpler now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants