Skip to content

Commit

Permalink
very rough first pass gemini support
Browse files Browse the repository at this point in the history
There might be a mismatch in the JSON structure of the initial tool call and
subsequent tool turns as encoded in tool blocks.

Fixups:
remove id reference unavailable on gemeni

* gptel-gemini.el:
  • Loading branch information
psionic-k committed Feb 28, 2025
1 parent 383f104 commit a06ea68
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions gptel-gemini.el
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,36 @@ See generic implementation for full documentation."
(when-let* ((content (gptel--trim-prefixes
(buffer-substring-no-properties (point) prev-pt))))
(push (list :role "model" :parts (list :text content)) prompts)))
(`(tool . ,_id)
(save-excursion
;; XXX has not been tested at all 🤠
(condition-case-unless-debug _err
(let* ((tool-call (read (current-buffer)))
(name (plist-get tool-call :name))
(arguments (json-serialize (plist-get tool-call :args)
:null-object nil
:false-object :json-false)))
(push
(list :role "user"
:parts `(:functionResponse
;; XXX if the response is supposed to be
;; JSON, we have to de-serialize tool's
;; return value as JSON into the response
;; section of the tool result, then
;; re-serialize it from Elisp here.
(vector (string-trim
(buffer-substring-no-properties
(point) prev-pt)))))
prompts)
(push (list :role "model"
:parts
(vector `(:functionCall ( :name ,name
:args ,arguments))))
prompts))
((end-of-file invalid-read-syntax)
(message (format "Could not parse tool-call on line %s"
(line-number-at-pos (point))))))))
('ignore)
('nil
(if include-media
(when-let* ((content (gptel--gemini-parse-multipart
Expand Down

0 comments on commit a06ea68

Please sign in to comment.