|
6 | 6 | ;; Maintainer: Shen, Jen-Chieh <[email protected]> |
7 | 7 | ;; URL: https://github.com/emacs-openai/chatgpt |
8 | 8 | ;; 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")) |
10 | 10 | ;; Keywords: comm openai |
11 | 11 |
|
12 | 12 | ;; This file is not part of GNU Emacs. |
|
32 | 32 | ;;; Code: |
33 | 33 |
|
34 | 34 | (require 'cl-lib) |
| 35 | +(require 'let-alist) |
35 | 36 |
|
36 | 37 | (require 'openai) |
37 | | -(require 'let-alist) |
| 38 | +(require 'lv) |
38 | 39 | (require 'ht) |
39 | 40 |
|
40 | 41 | (defgroup chatgpt nil |
@@ -227,6 +228,40 @@ The data is consist of ROLE and CONTENT." |
227 | 228 | :temperature chatgpt-temperature |
228 | 229 | :user user))))) |
229 | 230 |
|
| 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 | + |
230 | 265 | ;; |
231 | 266 | ;;; Entry |
232 | 267 |
|
|
0 commit comments