Skip to content

Commit 27c09ea

Browse files
committed
Add model module
1 parent d83333b commit 27c09ea

File tree

3 files changed

+105
-1
lines changed

3 files changed

+105
-1
lines changed

Eask

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@
1515

1616
(depends-on "emacs" "26.1")
1717
(depends-on "request")
18+
(depends-on "tblui")
1819

1920
(setq network-security-level 'low) ; see https://github.com/jcs090218/setup-emacs-windows/issues/156#issuecomment-932956432

google-gemini-model.el

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
;;; google-gemini-model.el --- More info regarding models -*- lexical-binding: t; -*-
2+
3+
;; Copyright (C) 2024 Shen, Jen-Chieh
4+
5+
;; This file is not part of GNU Emacs.
6+
7+
;; This program is free software: you can redistribute it and/or modify
8+
;; it under the terms of the GNU General Public License as published by
9+
;; the Free Software Foundation, either version 3 of the License, or
10+
;; (at your option) any later version.
11+
12+
;; This program is distributed in the hope that it will be useful,
13+
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
;; GNU General Public License for more details.
16+
17+
;; You should have received a copy of the GNU General Public License
18+
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
20+
;;; Commentary:
21+
;;
22+
;; More info regarding models.
23+
;;
24+
25+
;;; Code:
26+
27+
(require 'google-gemini)
28+
29+
;;
30+
;;; API
31+
32+
;;;###autoload
33+
(cl-defun google-gemini-model ( name
34+
callback
35+
&key
36+
(key google-gemini-key))
37+
"Send request to get model information."
38+
(google-gemini-request (concat google-gemini-generativelanguage-url
39+
"v1beta/models/" name "?key="
40+
key)
41+
:type "GET"
42+
:parser 'json-read
43+
:complete (cl-function
44+
(lambda (&key data &allow-other-keys)
45+
(funcall callback data)))))
46+
47+
;;;###autoload
48+
(cl-defun google-gemini-models ( callback
49+
&key
50+
(key google-gemini-key))
51+
"Send request to get a list of supported models."
52+
(google-gemini-request (concat google-gemini-generativelanguage-url
53+
"v1beta/models?key="
54+
key)
55+
:type "GET"
56+
:parser 'json-read
57+
:complete (cl-function
58+
(lambda (&key data &allow-other-keys)
59+
(funcall callback data)))))
60+
61+
;;
62+
;;; Application
63+
64+
;;;###autoload
65+
(defun google-gemini-model-info ()
66+
"Print a model information."
67+
(interactive)
68+
(if-let ((name (read-string "Name of the model: " "gemini-pro")))
69+
(google-gemini-model name (lambda (data) (message "%s" data)))
70+
(user-error "Abort, cancel get model info operation")))
71+
72+
(defvar google-gemini-model-entries nil
73+
"Async models entries.")
74+
75+
(tblui-define
76+
google-gemini-model
77+
"Google Gemini Model" "Display models information from Google Gemini."
78+
(lambda () google-gemini-model-entries)
79+
[("Name" 30 nil)
80+
("Version" 5 nil)
81+
("Description" 5 nil)]
82+
nil)
83+
84+
;;;###autoload
85+
(defun google-gemini-list-models ()
86+
"List out all supported models."
87+
(interactive)
88+
(setq google-gemini-model-entries nil) ; reset
89+
(google-gemini-models (lambda (data)
90+
(let-alist data
91+
(mapc (lambda (model)
92+
(let-alist model
93+
(push (list (length google-gemini-model-entries)
94+
(vector .name
95+
.version
96+
.description))
97+
google-gemini-model-entries)))
98+
.models))
99+
(google-gemini-model-goto-ui))))
100+
101+
(provide 'google-gemini-model)
102+
;;; google-gemini-model.el ends here

google-gemini.el

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
;; Maintainer: JenChieh <jcs090218@gmail.com>
77
;; URL: https://github.com/emacs-openai/google-gemini
88
;; Version: 0.1.0
9-
;; Package-Requires: ((emacs "26.1") (request "0.3.0"))
9+
;; Package-Requires: ((emacs "26.1") (request "0.3.0") (tblui "0.1.0"))
1010
;; Keywords: comm google gemini
1111

1212
;; This file is not part of GNU Emacs.
@@ -39,6 +39,7 @@
3939
(require 'json)
4040

4141
(require 'request)
42+
(require 'tblui)
4243

4344
(defgroup google-gemini nil
4445
"Elisp library for the Google Gemini API."

0 commit comments

Comments
 (0)