♻️: Untangle Gemini model and endpoint #212 (#213)

gptel-gemini.el (gptel-make-gemini): Decouple the Gemini model
from the API endpoint.  This is to support additional model
options in the future.
This commit is contained in:
Cash Prokop-Weaver 2024-03-10 21:02:42 -07:00 committed by GitHub
parent 3d6147830e
commit 3935a6dcf8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -115,7 +115,7 @@
(host "generativelanguage.googleapis.com") (host "generativelanguage.googleapis.com")
(protocol "https") (protocol "https")
(models '("gemini-pro")) (models '("gemini-pro"))
(endpoint "/v1beta/models/gemini-pro:")) (endpoint "/v1beta/models"))
"Register a Gemini backend for gptel with NAME. "Register a Gemini backend for gptel with NAME.
@ -126,8 +126,7 @@ CURL-ARGS (optional) is a list of additional Curl arguments.
HOST (optional) is the API host, defaults to HOST (optional) is the API host, defaults to
\"generativelanguage.googleapis.com\". \"generativelanguage.googleapis.com\".
MODELS is a list of available model names. Currently only MODELS is a list of available model names.
\"gemini-pro\" is available.
STREAM is a boolean to enable streaming responses, defaults to STREAM is a boolean to enable streaming responses, defaults to
false. false.
@ -135,8 +134,7 @@ false.
PROTOCOL (optional) specifies the protocol, \"https\" by default. PROTOCOL (optional) specifies the protocol, \"https\" by default.
ENDPOINT (optional) is the API endpoint for completions, defaults to ENDPOINT (optional) is the API endpoint for completions, defaults to
\"/v1beta/models/gemini-pro:streamGenerateContent\" if STREAM is true and \"/v1beta/models\".
\"/v1beta/models/gemini-pro:generateContent\" otherwise.
HEADER (optional) is for additional headers to send with each HEADER (optional) is for additional headers to send with each
request. It should be an alist or a function that retuns an request. It should be an alist or a function that retuns an
@ -156,17 +154,17 @@ function that returns the key."
:endpoint endpoint :endpoint endpoint
:stream stream :stream stream
:key key :key key
:url :url (lambda ()
(if stream (let ((method (if (and stream
(lambda () gptel-stream)
(concat protocol "://" host endpoint
(if gptel-stream
"streamGenerateContent" "streamGenerateContent"
"generateContent") "generateContent")))
"?key=" (gptel--get-api-key))) (format "%s://%s%s/%s:%s?key=%s"
(lambda () protocol
(concat protocol "://" host endpoint host
"generateContent" "?key=" endpoint
gptel-model
method
(gptel--get-api-key))))))) (gptel--get-api-key)))))))
(prog1 backend (prog1 backend
(setf (alist-get name gptel--known-backends (setf (alist-get name gptel--known-backends