Skip to content

Commit e06f122

Browse files
committed
Add display info
1 parent 04187e2 commit e06f122

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

Eask

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
(depends-on "emacs" "26.1")
1818
(depends-on "openai")
19+
(depends-on "lv")
1920
(depends-on "ht")
2021

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

chatgpt.el

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
;; Maintainer: Shen, Jen-Chieh <[email protected]>
77
;; URL: https://github.com/emacs-openai/chatgpt
88
;; Version: 0.1.0
9-
;; Package-Requires: ((emacs "26.1") (openai "0.1.0") (ht "2.0"))
9+
;; Package-Requires: ((emacs "26.1") (openai "0.1.0") (lv "0.0") (ht "2.0"))
1010
;; Keywords: comm openai
1111

1212
;; This file is not part of GNU Emacs.
@@ -32,9 +32,10 @@
3232
;;; Code:
3333

3434
(require 'cl-lib)
35+
(require 'let-alist)
3536

3637
(require 'openai)
37-
(require 'let-alist)
38+
(require 'lv)
3839
(require 'ht)
3940

4041
(defgroup chatgpt nil
@@ -227,6 +228,40 @@ The data is consist of ROLE and CONTENT."
227228
:temperature chatgpt-temperature
228229
:user user)))))
229230

231+
;;
232+
;;; Info
233+
234+
(defun chatgpt--pre-command-once (&rest _)
235+
"One time pre-command after Easky command."
236+
;; XXX: We pass on to next post-command!
237+
(remove-hook 'pre-command-hook #'chatgpt--pre-command-once)
238+
(add-hook 'post-command-hook #'chatgpt--post-command-once))
239+
240+
(defun chatgpt--post-command-once ()
241+
"One time post-command after info command."
242+
;; XXX: This will allow us to scroll in the lv's window!
243+
(unless (equal lv-wnd (selected-window))
244+
;; Once we select window other than lv's window, then we kill it!
245+
(remove-hook 'post-command-hook #'chatgpt--post-command-once)
246+
(lv-delete-window)))
247+
248+
(defun chatgpt-info ()
249+
"Show session information."
250+
(interactive)
251+
(lv-message
252+
(concat
253+
(format "model: %s" chatgpt-model) "\n"
254+
(format "prompt_tokens: %s | completion_tokens: %s | total_tokens: %s"
255+
(ht-get chatgpt-data 'prompt_tokens 0)
256+
(ht-get chatgpt-data 'completion_tokens 0)
257+
(ht-get chatgpt-data 'total_tokens 0))
258+
"\n"
259+
(format "max_tokens: %s" chatgpt-max-tokens) "\n"
260+
(format "temperature: %s" chatgpt-temperature) "\n"
261+
(format "user: %s" (chatgpt--get-user))))
262+
;; Register event to cancel lv window!
263+
(add-hook 'pre-command-hook #'chatgpt--pre-command-once))
264+
230265
;;
231266
;;; Entry
232267

0 commit comments

Comments
 (0)