Skip to content

Commit 3a8e76c

Browse files
committed
Add global params
1 parent 41f3e2a commit 3a8e76c

File tree

5 files changed

+62
-19
lines changed

5 files changed

+62
-19
lines changed

google-gemini-content.el

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
;;;###autoload
3333
(cl-defun google-gemini-content-generate ( text callback
3434
&key
35+
(parameters google-gemini-parameters)
3536
(content-type "application/json")
3637
(key google-gemini-key)
3738
(model "gemini-pro")
@@ -42,11 +43,22 @@
4243
max-output-tokens
4344
top-p
4445
top-k)
45-
"Send generate content request."
46+
"Send generate content request.
47+
48+
Arguments TEXT and CALLBACK are required for this type of request.
49+
TEXT is the content data. CALLBACK is the execuation after request is made.
50+
51+
Arguments PARAMETERS, CONTENT-TYPE, and KEY are global options;
52+
however, you can overwrite the value by passing it in.
53+
54+
The rest of the arugments are optional, please see Google Gemini API reference
55+
page for more information. Arguments here refer to MODEL, TEMPERATURE,
56+
STOP-SEQUENCES, MAX-OUTPUT-TOKENS, TOP-P, and TOP-K."
4657
(google-gemini-request (concat google-gemini-generativelanguage-url
4758
"v1beta/models/" model ":generateContent?key="
4859
key)
4960
:type "POST"
61+
:params parameters
5062
:headers (google-gemini--headers content-type)
5163
:data (google-gemini--json-encode
5264
`(("contents" . [(("parts" . [(("text" . ,text))]))])

google-gemini-count-tokens.el

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,22 @@
3030
;;;###autoload
3131
(cl-defun google-gemini-count-tokens ( text callback
3232
&key
33+
(parameters google-gemini-parameters)
3334
(content-type "application/json")
34-
(model "gemini-pro")
35-
(key google-gemini-key))
36-
"Send count tokens request."
35+
(key google-gemini-key)
36+
(model "gemini-pro"))
37+
"Send count tokens request.
38+
39+
Arguments PARAMETERS, CONTENT-TYPE, and KEY are global options;
40+
however, you can overwrite the value by passing it in.
41+
42+
The rest of the arugments are optional, please see Google Gemini API reference
43+
page for more information. Arguments here refer to MODEL."
3744
(google-gemini-request (concat google-gemini-generativelanguage-url
3845
"v1beta/models/" model ":countTokens?key="
3946
key)
4047
:type "POST"
48+
:params parameters
4149
:headers (google-gemini--headers content-type)
4250
:data (google-gemini--json-encode
4351
`(("contents" . [((parts . [((text . ,text))]))])))

google-gemini-embedding.el

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,22 @@
3232
;;;###autoload
3333
(cl-defun google-gemini-embedding ( text callback
3434
&key
35+
(parameters google-gemini-parameters)
3536
(content-type "application/json")
3637
(key google-gemini-key)
37-
(model "embedding-001")
38-
(category "HARM_CATEGORY_DANGEROUS_CONTENT")
39-
(threshold "BLOCK_ONLY_HIGH")
40-
stop-sequences
41-
temperature
42-
max-output-tokens
43-
top-p
44-
top-k)
45-
"Send generate content request."
38+
(model "embedding-001"))
39+
"Send generate content request.
40+
41+
Arguments PARAMETERS, CONTENT-TYPE, and KEY are global options;
42+
however, you can overwrite the value by passing it in.
43+
44+
The rest of the arugments are optional, please see Google Gemini API reference
45+
page for more information. Arguments here refer to MODEL."
4646
(google-gemini-request (concat google-gemini-generativelanguage-url
4747
"v1beta/models/" model ":embedContent?key="
4848
key)
4949
:type "POST"
50+
:params parameters
5051
:headers (google-gemini--headers content-type)
5152
:data (google-gemini--json-encode
5253
`(("model" . ,(concat "models/" model))

google-gemini-model.el

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,24 @@
3030
;;; API
3131

3232
;;;###autoload
33-
(cl-defun google-gemini-model ( name
33+
(cl-defun google-gemini-model ( model
3434
callback
3535
&key
36+
(parameters google-gemini-parameters)
3637
(key google-gemini-key))
37-
"Send request to get model information."
38+
"Send request to get model information.
39+
40+
Arguments MODEL and CALLBACK are required for this type of request.
41+
MODEL is the name of the model. CALLBACK is the execuation after request
42+
is made.
43+
44+
Arguments PARAMETERS, and KEY are global options; however, you can overwrite the
45+
value by passing it in."
3846
(google-gemini-request (concat google-gemini-generativelanguage-url
39-
"v1beta/models/" name "?key="
47+
"v1beta/models/" model "?key="
4048
key)
4149
:type "GET"
50+
:params parameters
4251
:parser 'json-read
4352
:complete (cl-function
4453
(lambda (&key data &allow-other-keys)
@@ -47,12 +56,20 @@
4756
;;;###autoload
4857
(cl-defun google-gemini-models ( callback
4958
&key
59+
(parameters google-gemini-parameters)
5060
(key google-gemini-key))
51-
"Send request to get a list of supported models."
61+
"Send request to get a list of supported models.
62+
63+
Arguments CALLBACK is required for this type of request.
64+
CALLBACK is the execuation after request is made.
65+
66+
Arguments PARAMETERS, and KEY are global options; however, you can overwrite the
67+
value by passing it in."
5268
(google-gemini-request (concat google-gemini-generativelanguage-url
5369
"v1beta/models?key="
5470
key)
5571
:type "GET"
72+
:params parameters
5673
:parser 'json-read
5774
:complete (cl-function
5875
(lambda (&key data &allow-other-keys)
@@ -65,8 +82,8 @@
6582
(defun google-gemini-model-info ()
6683
"Print a model information."
6784
(interactive)
68-
(if-let ((name (read-string "Name of the model: " "gemini-pro")))
69-
(google-gemini-model name (lambda (data) (message "%s" data)))
85+
(if-let ((model (read-string "Name of the model: " "gemini-pro")))
86+
(google-gemini-model model (lambda (data) (message "%s" data)))
7087
(user-error "Abort, cancel get model info operation")))
7188

7289
(defvar google-gemini-model-entries nil

google-gemini.el

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ auth-source is provided for convenience.")
7474
:type 'string
7575
:group 'google-gemini)
7676

77+
(defcustom google-gemini-parameters '()
78+
"The parameters for the Google Gemini request."
79+
:type 'list
80+
:group 'openai)
81+
7782
;;;###autoload
7883
(defun google-gemini-key-auth-source (&optional base-url)
7984
"Retrieve the Google Gemini API key from auth-source given a BASE-URL.

0 commit comments

Comments
 (0)