Skip to content

Commit 92972cd

Browse files
committed
Done first api
1 parent 19ff023 commit 92972cd

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

google-gemini-content.el

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@
2929
;;
3030
;;; API
3131

32+
(defun google-gemini-content-make-contents (text)
33+
"Create a contents value."
34+
`((parts . [((text . ,text))])))
35+
3236
;;;###autoload
33-
(cl-defun google-gemini-generate-content ( contents callback
37+
(cl-defun google-gemini-content-generate ( contents callback
3438
&key
3539
(content-type "application/json"))
3640
"Send generate content request."
@@ -39,7 +43,7 @@
3943
:type "POST"
4044
:headers (google-gemini--headers content-type)
4145
:data (google-gemini--json-encode
42-
`(("contents" . ,contents)))
46+
`(("contents" . [,contents])))
4347
:parser 'json-read
4448
:complete (cl-function
4549
(lambda (&key data &allow-other-keys)
@@ -49,10 +53,19 @@
4953
;;; Application
5054

5155
;;;###autoload
52-
(defun google-gemini-say ()
56+
(defun google-gemini-content-prompt ()
5357
"Start making a conversation to Google Gemini."
5458
(interactive)
55-
)
59+
(if-let* ((text (read-string "Content: "))
60+
(contents (google-gemini-content-make-contents text)))
61+
(google-gemini-content-generate contents
62+
(lambda (data)
63+
(let-alist data
64+
(let-alist (elt .candidates 0)
65+
(let-alist .content
66+
(let-alist (elt .parts 0)
67+
(message "%s" .text)))))))
68+
(user-error "Abort, cancel generate content operation")))
5669

5770
(provide 'google-gemini-content)
5871
;;; google-gemini-content.el ends here

0 commit comments

Comments
 (0)