karthink / gptel

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

Add gemini backend support? #149

Closed mrdylanyin closed 6 months ago

mrdylanyin commented 6 months ago

Gemini is Google’s AI model and free for personal usage. User can get an API key via their page on Google AI Studio

karthink commented 6 months ago

Sure. Would you be interested in adding it?

On Sun, Dec 17, 2023, 5:41 AM mrdylanyin @.***> wrote:

Gemini is Google’s AI model and free for personal usage. User can get an API key via their page on Google AI Studio https://makersuite.google.com/app/apikey

— Reply to this email directly, view it on GitHub https://github.com/karthink/gptel/issues/149, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACBVOLFR3ALHCTTHESC23EDYJ3ZAHAVCNFSM6AAAAABAYLXYUOVHI2DSMVQWIX3LMV43ASLTON2WKOZSGA2DKMRSGQYTANY . You are receiving this because you are subscribed to this thread.Message ID: @.***>

mrdylanyin commented 6 months ago

I really want to make this feature happen, but truth be told, I'm a newbie when it comes to writing Emacs Lisp. Spent a few hours digging through the source code, and I'm still clueless on where to begin. Apologies for that.

karthink commented 6 months ago

@mrdylanyin Almost all of the code is LLM agnostic, so it will not need changing. You also do not need to understand these parts to add a new backend. Assuming gemini has a http API and replies with JSON, there are only three API-specific functions (technically implementations of generic methods) needed:

If streaming responses are supported:

If streaming responses are not supported:

You can look at the implementation of these methods (as cl-defmethod) in the files gptel-openai.el and gptel-ollama.el. You might be able to get gemini working just by tweaking one of these.