Last active
November 2, 2024 14:50
-
-
Save ckopsa/c55bf8cc25df8a4a87c6993bdce3573e to your computer and use it in GitHub Desktop.
Uses chatgpt-shell to make spelling and grammar fixes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun chatgpt-shell-check-and-correct-paragraph () | |
"Check and correct the current paragraph using ChatGPT." | |
(interactive) | |
(let* ((bounds (bounds-of-thing-at-point 'paragraph)) | |
(start (car bounds)) | |
(end (cdr bounds)) | |
(original-text (buffer-substring-no-properties start end)) | |
(point-offset (- end (point))) ; Save the offset of point from end | |
(checked-text (chatgpt-shell-check-paragraph original-text))) | |
(when checked-text | |
(save-excursion | |
(goto-char start) | |
(delete-region start end) | |
(insert "\n") ; Insert a newline here | |
(insert checked-text)) | |
;; Move the point to its new position relative to the end | |
(goto-char (- (cdr (bounds-of-thing-at-point 'paragraph)) point-offset))))) | |
(defun chatgpt-shell-check-paragraph (text) | |
"Send TEXT to ChatGPT for spell and grammar checking." | |
(let ((response (chatgpt-shell-post-prompt | |
(concat | |
"Please correct the spelling and grammar of the following paragraph." | |
"Maintain existing org-mode syntax expressions like =this= and *this*." | |
"Only return the corrected paragraph, not the original text or this prompt." | |
"Here's the text:\n\n" text) | |
nil "gpt-3.5-turbo" nil nil nil nil))) | |
response)) | |
;; Optionally bind to a key | |
(global-set-key (kbd "C-c s") 'chatgpt-shell-check-and-correct-paragraph) |
chatgpt-shell-post-prompt
function is removed from https://github.com/xenodium/chatgpt-shell :(
This chatgpt-shell-check-paragraph
version works with chatgpt-shell commit 06a66734f429638de5fc503adaa5e969f94ed2bd
(defun chatgpt-shell-check-paragraph (text)
"Send TEXT to ChatGPT for spell and grammar checking."
(chatgpt-shell-post-chatgpt-messages :messages `(((role . "user") (content . ,(concat
"Please correct the spelling and grammar of the following paragraph."
"Maintain existing org-mode syntax expressions like =this= and *this*."
"Only return the corrected paragraph, not the original text or this prompt."
"Here's the text:\n\n" text))))))
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
great thing!
I tried to get it work also with ediff or any way to see what has changed, and maybe use another solution. Any ideas?