Skip to content

Commit

Permalink
feat: Add chat points
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs090218 committed Sep 13, 2023
1 parent b1b4f6d commit 34376e9
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions chatgpt.el
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@
(defvar-local chatgpt-chat-history nil
"The chat history use to send request.")

(defvar-local chatgpt-chat-points nil
"Buffer points every time we add a new message.")

(defvar-local chatgpt-requesting-p nil
"Non-nil when requesting; waiting for the response.")

Expand Down Expand Up @@ -228,6 +231,10 @@ Display buffer from BUFFER-OR-NAME."
"user" ; this is free?
openai-user))

(defun chatgpt-chat-points ()
"Return chat points in correct order."
(reverse chatgpt-chat-points))

;;
;;; Instances

Expand Down Expand Up @@ -340,10 +347,17 @@ information we want to display."
(unless chatgpt-animate-text
(chatgpt--create-tokens-overlay .prompt_tokens .completion_tokens .total_tokens))))))

(defun chatgpt--add-chat-point ()
"Add a chat point."
(if chatgpt-chat-points
(push (point-max) chatgpt-chat-points)
(push (point-min) chatgpt-chat-points)))

(defun chatgpt--add-message (role content)
"Add a message to history.
The data is consist of ROLE and CONTENT."
(chatgpt--add-chat-point)
(setq chatgpt-chat-history
(vconcat (or chatgpt-chat-history '[])
`[((role . ,role)
Expand Down Expand Up @@ -681,6 +695,7 @@ The data is consist of ROLE and CONTENT."
"Major mode for `chatgpt-mode'.
\\<chatgpt-mode-map>"
(buffer-disable-undo)
(setq-local buffer-read-only t)
(font-lock-mode -1)
(add-hook 'kill-buffer-hook #'chatgpt-mode--kill-buffer-hook nil t)
Expand Down

0 comments on commit 34376e9

Please sign in to comment.