Skip to content

Commit 9a18f68

Browse files
committed
update
1 parent 999e3a7 commit 9a18f68

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

chatgpt-shell-google.el

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ If you use Gemini through a proxy service, change the URL base."
5555

5656
;; https://ai.google.dev/gemini-api/docs/tokens
5757
;; A token is equivalent to _about_ 4 characters.
58-
(cl-defun chatgpt-shell-google-make-model (&key version short-version path token-width context-window)
58+
(cl-defun chatgpt-shell-google-make-model (&key version short-version path token-width context-window grounding-search)
5959
"Create a Google model.
6060
6161
Set VERSION, SHORT-VERSION, PATH, TOKEN-WIDTH, CONTEXT-WINDOW and
@@ -77,6 +77,7 @@ VALIDATE-COMMAND handler."
7777
(:path . ,path)
7878
(:token-width . ,token-width)
7979
(:context-window . ,context-window)
80+
(:grounding-search . ,grounding-search)
8081
(:url-base . chatgpt-shell-google-api-url-base)
8182
(:handler . chatgpt-shell-google--handle-gemini-command)
8283
(:filter . chatgpt-shell-google--extract-gemini-response)
@@ -93,6 +94,7 @@ VALIDATE-COMMAND handler."
9394
(list (chatgpt-shell-google-make-model :version "gemini-2.0-flash"
9495
:short-version "2.0-flash"
9596
:path "/v1beta/models/gemini-2.0-flash"
97+
:grounding-search t
9698
:token-width 4
9799
:context-window 1048576)
98100
(chatgpt-shell-google-make-model :version "gemini-1.5-pro-latest"
@@ -155,12 +157,12 @@ or
155157
"Create the API headers."
156158
(list "Content-Type: application/json; charset=utf-8"))
157159

158-
(cl-defun chatgpt-shell-google--make-payload (&key _model context settings)
160+
(cl-defun chatgpt-shell-google--make-payload (&key model context settings)
159161
"Create the API payload using MODEL CONTEXT and SETTINGS."
160162
(chatgpt-shell-google--make-gemini-payload
161163
:context context
162-
:temperature (map-elt settings :temperature)
163-
:system-prompt (map-elt settings :system-prompt)))
164+
:model model
165+
:settings settings))
164166

165167
(cl-defun chatgpt-shell-google--handle-gemini-command (&key model command context shell settings)
166168
"Handle Gemini COMMAND (prompt) using MODEL, CONTEXT, SHELL, and SETTINGS."
@@ -172,27 +174,27 @@ or
172174
:data (chatgpt-shell-google--make-gemini-payload
173175
:prompt command
174176
:context context
175-
:temperature (map-elt settings :temperature)
176-
:system-prompt (map-elt settings :system-prompt))
177+
:model model
178+
:settings settings)
177179
:headers (list "Content-Type: application/json; charset=utf-8")
178180
:filter #'chatgpt-shell-google--extract-gemini-response
179181
:shell shell))
180182

181-
(cl-defun chatgpt-shell-google--make-gemini-payload (&key prompt context system-prompt temperature)
183+
(cl-defun chatgpt-shell-google--make-gemini-payload (&key prompt context settings model)
182184
"Create the request payload.
183185
184186
Compose using PROMPT, CONTEXT, SYSTEM-PROMPT and TEMPERATURE."
185187
(append
186-
(when system-prompt
187-
`((system_instruction . ((parts . ((text . ,system-prompt)))))))
188+
(when (map-elt settings :system-prompt)
189+
`((system_instruction . ((parts . ((text . ,(map-elt settings :system-prompt))))))))
188190
`((contents . ,(vconcat
189191
(chatgpt-shell-google--gemini-user-model-messages
190192
(append context
191193
(when prompt
192194
(list (cons prompt nil))))))))
193-
(when chatgpt-shell-google-enable-grounding-search
195+
(when (map-elt model :grounding-search)
194196
'((tools . ((google_search . ())))))
195-
`((generation_config . ((temperature . ,(or temperature 1))
197+
`((generation_config . ((temperature . ,(or (map-elt settings :temperature) 1))
196198
;; 1 is most diverse output.
197199
(topP . 1))))))
198200

0 commit comments

Comments
 (0)