blob: 2240d0ac2e9bed6405ceba56bfbc0d41dbbf2911 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
;;; ai-config.el --- Configuration for AI Integrations -*- lexical-binding: t; -*-
;;; Commentary:
;; There are several workflows available. Here are the ones I use most.
;; - Launch GPTel and chat with the AI in a separate buffer.
;; Chatting is fine, but it can mean cutting and pasting code back and forth
;; between buffers.
;; - Select a region and launch GPTel.
;; The region is automatically inserted into the buffer making it easy to
;; simply ask a question after it's read the code.
;; Note that you can save a file, then turn on gptel-mode to resume your
;; conversation.
;; Remember that sending the message requires C-<return>.
;;; Code:
;; ----------------------------------- GPTel -----------------------------------
;; integration with ChatGPT and other large language models.
(use-package gptel
:defer .5
:bind
("C-h G" . gptel)
(:map gptel-mode-map
("C-<return>" . gptel-send))
:custom
;; (gptel-model "gpt-3.5-turbo-16k") ;; next best alternative
(gptel-model "gpt-4")
(gptel-default-mode 'org-mode)
:config
(setq gptel-directives
'((default
. "You are a large language model living in Emacs and a careful and
knowledgeable emacs-lisp programmer. Respond accurately and concisely.")
(programming
. "You are a large language model and a careful programmer. Provide code
and only code as output without any additional text, prompt or note.")
(writing
. "You are a large language model and a writing assistant. Respond
concisely.")
(chat
. "You are a large language model and a conversation partner. Respond
concisely.")))
;; grab the secret from ~/.authinfo.gpg
(setq gptel-api-key (auth-source-pick-first-password :host "api.openai.com")))
;; ----------------------------- Gptel Send Region -----------------------------
;; convenience function to send a selection to Gptel.
(defun cj/gptel-send-region (&optional prefix)
"Verify a region is selected and call gptel-send with PREFIX."
(interactive "P")
(if (use-region-p)
(gptel-send (prefix-numeric-value prefix))
(error "No region selected")))
(global-set-key (kbd "C-; g") 'cj/gptel-send-region)
(provide 'ai-config)
;;; ai-config.el ends here
|