~abcdw/rde-devel

rde: features: Add emacs-gptel v1 SUPERSEDED

Nicolas Graves: 1
 features: Add emacs-gptel

 1 files changed, 46 insertions(+), 1 deletions(-)
Also might be worth integrating with embark as per gptel-quick:

https://github.com/karthink/gptel-quick?tab=readme-ov-file#setup
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~abcdw/rde-devel/patches/56956/mbox | git am -3
Learn more about email & git

[PATCH rde] features: Add emacs-gptel Export this patch

---
 src/rde/features/emacs-xyz.scm | 47 +++++++++++++++++++++++++++++++++-
 1 file changed, 46 insertions(+), 1 deletion(-)

diff --git a/src/rde/features/emacs-xyz.scm b/src/rde/features/emacs-xyz.scm
index 5bad5e97..9eda9e99 100644
--- a/src/rde/features/emacs-xyz.scm
+++ b/src/rde/features/emacs-xyz.scm
@@ -3,7 +3,7 @@
;;; Copyright © 2022, 2023, 2024 Andrew Tropin <andrew@trop.in>
;;; Copyright © 2022 Samuel Culpepper <samuel@samuelculpepper.com>
;;; Copyright © 2022 Demis Balbach <db@minikn.xyz>
;;; Copyright © 2022, 2023, 2024 Nicolas Graves <ngraves@ngraves.fr>
;;; Copyright © 2022-2025 Nicolas Graves <ngraves@ngraves.fr>
;;; Copyright © 2022, 2023 Miguel Ángel Moreno <me@mianmoreno.com>
;;; Copyright © 2023 Benoit Joly <benoit@benoitj.ca>
;;; Copyright © 2024 jgart <jgart@dismail.de>
@@ -66,6 +66,7 @@
            feature-emacs-eat
            feature-emacs-eshell
            feature-emacs-calc
            feature-emacs-gptel
            feature-emacs-re-builder
            feature-emacs-comint
            feature-emacs-help
@@ -1351,6 +1352,50 @@ it every EXCHANGE-UPDATE-INTERVAL days."
             (emacs-calc-currency . ,emacs-calc-currency)))
   (home-services-getter get-home-services)))

(define* (feature-emacs-gptel
          #:key
          (emacs-gptel emacs-gptel)
          (gptel-api-key (list "pass" "show" "gptel-api-key")))
  "Configure Gptel, a simple and unintrusive LLM client for Emacs.
GPTEL-API-KEY is a list of program and arguments that are called by Emacs and
that returns a string API key (safer defaults than having it as a string
on-disk)."
  (ensure-pred file-like? emacs-gptel)
  (ensure-pred list-of-strings? gptel-api-key)

  (define emacs-f-name 'gptel)
  (define f-name (symbol-append 'emacs emacs-f-name))

  (define (get-home-services config)
    "Return home services related to Gptel."
    (list
     (rde-elisp-configuration-service
      emacs-f-name
      config
      `((with-eval-after-load 'gptel
          (defun rde-gptel-get-api-key ()
            (string-trim-right
             (with-output-to-string
               (let ((exit (call-process
                            ,(if (string-prefix? "pass" (car gptel-api-key))
                                 (file-append
                                  (get-value 'password-store config)
                                  "/bin/" (car gptel-api-key))
                                 (car gptel-api-key))
                            nil " *string-output*" nil
                            ,@(cdr gptel-api-key))))
                 (or (zerop exit)
                     (error "Failed to get gptel-api-key with exit code %d"
                            exit))))))
          (setq gptel-api-key 'rde-gptel-get-api-key)))
      #:elisp-packages (list emacs-gptel))))

  (feature
   (name f-name)
   (values `((,f-name . #t)
             (emacs-gptel . ,emacs-gptel)))
   (home-services-getter get-home-services)))

(define* (feature-emacs-re-builder
          #:key
          (re-syntax 'rx)
-- 
2.47.1
Hi!

WDYT of making the file format style configurable?

Similar to here?

https://git.sr.ht/~whereiseveryone/confetti/tree/e/conf/confetti/features/gptel.scm#L20

For example, I might want to use markdown instead.

Thanks for working on this.