From b8d1c727a1109628e4cb7090a5e697df07eb20e3 Mon Sep 17 00:00:00 2001 From: Andrea Ciceri Date: Wed, 1 May 2024 09:49:02 +0200 Subject: [PATCH] Use `gptel` --- init.el | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/init.el b/init.el index 8557a69..f33b0a5 100644 --- a/init.el +++ b/init.el @@ -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