Use gptel
All checks were successful
/ test (push) Successful in 23s

This commit is contained in:
Andrea Ciceri 2024-05-01 09:49:02 +02:00
parent 74e0f203bb
commit b8d1c727a1
Signed by: aciceri
SSH key fingerprint: SHA256:/AagBweyV4Hlfg9u092n8hbHwD5fcB6A3qhDiDA65Rg

22
init.el
View file

@ -794,7 +794,29 @@ This is meant to be an helper to be called from the window manager."
("C-c n l" . consult-org-roam-forward-links)
("C-c n r" . consult-org-roam-search))
(use-package gptel
:custom
(gptel-api-key (getenv "OPENAI_API_KEY"))
:config
(defun ccr/suggest-eshell-command ()
(interactive)
(save-excursion
(eshell-bol)
(let ((start-pos (point))
(end-pos (line-end-position)))
(gptel-request
(buffer-substring-no-properties start-pos end-pos) ;the prompt
:system "You are proficient with emacs shell (eshell), translate the following to something I could directly prompt to the shell. Your responses should only be code, without explanation or formatting."
:buffer (current-buffer)
:context (cons (set-marker (make-marker) start-pos)
(set-marker (make-marker) end-pos))
:callback
(lambda (response info)
(if (not response)
(message "ChatGPT response failed with: %s" (plist-get info :status))
(kill-region start-pos end-pos)
(insert response)))))))
)
(use-package copilot
:custom