Closed moritzschaefer closed 11 months ago
There are many ways to do it:
Save the gptel buffer to a file as needed. I take it this is the step you want to automate.
Save the buffer to a file when gptel-mode
is turned on: (Note: untested)
(defun my/gptel-write-buffer ()
"Save buffer to disk when starting gptel"
(unless (buffer-file-name (current-buffer))
(let ((suffix (format-time-string "%Y%m%dT%H%M" (current-time)))
(chat-dir "~/chatgpt-log"))
(unless (file-directory-p chat-dir)
(make-directory chat-dir :parents))
(write-file (expand-file-name (concat "gptel-" suffix ".txt") chat-dir)))))
(add-hook 'gptel-mode-hook #'my/gptel-write-buffer)
This will save new gptel sessions to `~/chatgpt-log` with names like `gptel-20231105T1026.txt`. Or you can save to `default-directory`, or to `(project-root (project-current))` to save them at the root of your current project in Emacs.
- I use a [single file per project](https://github.com/karthink/.emacs.d/blob/master/init.el#L3601) (always named `Chat.org`) to keep persistent logs of ChatGPT conversations, and bind summoning it to the project keymap (`C-x p`), where all the other project commands are. Chat topics are separated by Org headers with `gptel-set-topic`.
This is a feature best tailored by users for their individual workflows, and thus not something I plan to implement in gptel -- so I'm moving this thread to the [discussions](https://github.com/karthink/gptel/discussions) section.
It would be nice to have the configurable option to automatically associated the gptel buffers (named <ChatGPT #n> by default with a file (e.g. in a configurable directory with file name.txt). This way, without extra effort, one can maintain a well-accessible history of chat interactions.
If not within
gptel
, do you have a recommendation how to implement this in the easiest manner?