Default to creating a new buffer when invoking gptel
This commit is contained in:
parent
6898a3e8e5
commit
d1147a81c3
@ -6,6 +6,29 @@
|
|||||||
(use-package gptel
|
(use-package gptel
|
||||||
:commands (gptel-request)
|
:commands (gptel-request)
|
||||||
:config
|
:config
|
||||||
|
;; Default to creating a new buffer when invoking gptel
|
||||||
|
(defun gptel-before-advice (name &optional _ initial interactivep)
|
||||||
|
(interactive
|
||||||
|
(let* ((backend (default-value 'gptel-backend))
|
||||||
|
(backend-name
|
||||||
|
(generate-new-buffer-name (format "*%s*" (gptel-backend-name backend)))))
|
||||||
|
(list (read-buffer "Create or choose gptel buffer: "
|
||||||
|
backend-name nil ; DEFAULT and REQUIRE-MATCH
|
||||||
|
(lambda (b) ; PREDICATE
|
||||||
|
(buffer-local-value 'gptel-mode
|
||||||
|
(get-buffer (or (car-safe b) b)))))
|
||||||
|
(condition-case nil
|
||||||
|
(gptel--get-api-key
|
||||||
|
(gptel-backend-key backend))
|
||||||
|
((error user-error)
|
||||||
|
(setq gptel-api-key
|
||||||
|
(read-passwd
|
||||||
|
(format "%s API key: " backend-name)))))
|
||||||
|
(and (use-region-p)
|
||||||
|
(buffer-substring (region-beginning)
|
||||||
|
(region-end)))
|
||||||
|
t))))
|
||||||
|
(advice-add 'gptel :before #'gptel-before-advice)
|
||||||
(defvar gptel-backend-openai (gptel-make-openai "ChatGPT"
|
(defvar gptel-backend-openai (gptel-make-openai "ChatGPT"
|
||||||
:key #'gptel-api-key-from-auth-source
|
:key #'gptel-api-key-from-auth-source
|
||||||
:stream t
|
:stream t
|
||||||
|
Loading…
Reference in New Issue
Block a user