From bcb8d468a62a18424a075f3938a76db6494895c4 Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Mon, 15 Jul 2024 16:10:55 -0400 Subject: [PATCH] Add function to generate commit messages with gptel --- emacs/.emacs.d/config/init-ai.el | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/emacs/.emacs.d/config/init-ai.el b/emacs/.emacs.d/config/init-ai.el index c706c1a..0b62d61 100644 --- a/emacs/.emacs.d/config/init-ai.el +++ b/emacs/.emacs.d/config/init-ai.el @@ -21,6 +21,26 @@ (embark-general-map "?" #'gptel-quick)) +(defun gptel-commit-message () + "Generate a commit message via gptel." + (interactive) + (unless git-commit-mode + (user-error "Not in a git commit buffer!")) + (let* ((diff-buf (magit-get-mode-buffer 'magit-diff-mode)) + (diff (with-current-buffer diff-buf + (buffer-substring-no-properties + (point-min) + ;; Skip the last line, which is just the [back] button + (save-excursion + (goto-char (point-max)) + (forward-line -1) + (point))))) + (prompt (format "%s\n\nWrite a clear, concise commit message for this diff. The first line should succinctly summarize the changes made and should be no more than 50 characters. If additional context is needed, include it in an additional paragraph separate by a blank line from the first line." diff))) + (message "Generating commit message...") + (gptel-request prompt + :stream t + :system "You are an experienced software engineer writing a commit message."))) + (use-package llama :straight `(:local-repo ,(expand-file-name "packages/llama" user-emacs-directory) :type nil) :load-path "packages/llama"