Skip to content

Commit b8e1d80

Browse files
committed
Merge remote-tracking branch 'origin/main' into work-refactor-merge-configs
2 parents 082640d + ecd3e37 commit b8e1d80

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

lisp/init-help.el

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,50 @@
117117
:config
118118
(bind-key (kbd "d") #'dictionary-lookup-definition 'rb-user-keymap))
119119

120+
;; ----------------------------------------------------------------------------
121+
;; GPTel - LLM interface for emacs
122+
;; ----------------------------------------------------------------------------
123+
124+
(when-home
125+
(use-package gptel
126+
:ensure (:source "MELPA")
127+
:config
128+
(setq gptel-api-key (lambda () (getenv "OPENAI_API_KEY")))
129+
(setq gptel-model 'gpt-4.1-nano)
130+
(setq gptel-default-mode 'markdown-mode)
131+
(bind-key (kbd "C-c RET") 'gptel-send global-map)
132+
(bind-key (kbd "g") 'gptel-menu rb-help-keymap)
133+
(bind-key (kbd "c") 'gptel rb-help-keymap)
134+
(add-to-list 'gptel-directives '(verify . "You are a large language model living in Emacs and a helpful assistant.
135+
Please check the following text for semantical errors (ignore notation,
136+
as the text might be org-mode markup language), and if you see mistakes
137+
make a of the mistakes with brief explanations."))
138+
)
139+
140+
141+
(defun rb/gptel-verify ()
142+
"Ask an LLM to check selected text for errors."
143+
(interactive)
144+
(let* ((buffer-name "*gptel-out*")
145+
(rb-buf (get-buffer-create buffer-name)))
146+
(with-current-buffer rb-buf
147+
(setq-local buffer-read-only nil)
148+
(erase-buffer))
149+
(gptel-request nil
150+
:callback (lambda (result info) (if (stringp result) (progn (with-current-buffer rb-buf
151+
(insert result)
152+
(help-mode)
153+
(setq-local buffer-read-only t)
154+
(display-buffer rb-buf)))))
155+
:stream nil
156+
:system "You are a large language model living in Emacs and a helpful assistant.
157+
Please check the following knowledge base snippet for errors, and if you see mistakes make
158+
a list of the mistakes with brief explanations and suggestion for improvement. Only focus on the correctness of the content and IGNORE grammatical and punctuational errors, or tags like :CARD:, since they are part of the markup language (org)! Make sure to output only a single list of issues and their explanations!")
159+
)
160+
nil)
161+
162+
(bind-key (kbd "v") 'rb/gptel-verify rb-help-keymap)
163+
)
120164

121165
(provide 'init-help)
122166

0 commit comments

Comments
 (0)