diff --git a/modules/ai/siren-chatgpt.el b/modules/ai/siren-chatgpt.el index 59b4fd0..5ec4ca6 100644 --- a/modules/ai/siren-chatgpt.el +++ b/modules/ai/siren-chatgpt.el @@ -23,7 +23,7 @@ auth-source. If LOGIN is non-nil, use that value to retrieve the" (let ((login (siren-chatgpt--login-user))) (or (and siren-chatgpt--api-key-login (string= siren-chatgpt--api-key-login login)) - (let ((api-key (auth-source-pick-first-password :host "openai.com" + (let ((api-key (auth-source-pick-first-password :host "api.openai.com" :user login))) (if api-key (progn @@ -57,10 +57,13 @@ their model settings are kept in sync with `siren-chatgpt-model'.") "gpt-3.5-turbo-16k" "gpt-4" "gpt-4-32k" - "gpt-4-turbo-preview") + "gpt-4-turbo" + "gpt-4-turbo-preview" + "gpt-4o" + "gpt-4o-2024-05-13") "List of supported models.") -(defcustom siren-chatgpt-model "gpt-4-turbo-preview" +(defcustom siren-chatgpt-model "gpt-4o" "The model to use for chatgpt." :type '(choice (mapcar (lambda (model) (list 'const model)) siren-chatgpt-models)) @@ -77,7 +80,7 @@ their model settings are kept in sync with `siren-chatgpt-model'.") Used to allow different API keys for different models." (cond ;; ((string-prefix-p "gpt-4" siren-chatgpt-model) "gpt-4") - (t "default"))) + (t "apikey"))) (defun siren-chatgpt-select-model () "Select a model to use for chatgpt." diff --git a/modules/ai/siren-gptel.el b/modules/ai/siren-gptel.el index 66c8ac9..856b8a1 100644 --- a/modules/ai/siren-gptel.el +++ b/modules/ai/siren-gptel.el @@ -9,10 +9,53 @@ (require 'siren-chatgpt) (use-package gptel + :hook + (gptel-mode . siren-gptel-setup-auto-save) + :general ("C-c C-q" 'siren-gptel) + (:keymaps 'gptel-mode-map + "C-c C-" 'gptel-send) :preface + (defgroup siren-gptel nil + "jimeh's Emacs Siren: gptel configuration." + + :group 'gptel) + + (defcustom siren-gptel-history-dir (expand-file-name "gptel-history" user-emacs-directory) + "Directory to save GPTel chat sessions upon buffer close." + :type 'string + :group 'siren-gptel) + + (defun siren-gptel--generate-filename () + "Generate a filename with the buffer creation date, time." + (let* ((time (or (buffer-local-value 'siren-gptel-buffer-create-time (current-buffer)) + (current-time))) + (timestamp (format-time-string "%Y%m%d_%H%M%S" time))) + (concat (file-name-as-directory siren-gptel-history-dir) "gptel_" timestamp ".org"))) + + (defun siren-gptel-save-session () + "Save the current GPTel chat session to a file." + (interactive) + (when (bound-and-true-p gptel-mode) + (let* ((filename (siren-gptel--generate-filename)) + (dirname (file-name-directory filename)) + (content (buffer-string))) + (unless (file-directory-p dirname) + (make-directory dirname t)) + (with-temp-buffer + (insert content) + (write-file filename)) + (message "Session saved to %s" filename)))) + + (defun siren-gptel-setup-auto-save () + "Setup auto-save for GPTel chat sessions." + (unless (and buffer-file-name + (string-prefix-p siren-gptel-history-dir (file-name-directory buffer-file-name))) + (setq-local siren-gptel-buffer-create-time (current-time)) + (add-hook 'kill-buffer-hook 'siren-gptel-save-session nil t))) + (defun siren-gptel () "Interactively call gptel, or gptel-send with prefix if region is active." (interactive)