From a64ff2b145b2ef83e8b087aa18cbab165232e8a4 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Tue, 2 Sep 2025 12:36:34 -0500 Subject: gptel should use projectile to add file to context if in project --- modules/ai-config.el | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/modules/ai-config.el b/modules/ai-config.el index 18c1e8cb..72219c1b 100644 --- a/modules/ai-config.el +++ b/modules/ai-config.el @@ -140,14 +140,30 @@ ;; ---- Auth: pick the API key from your auth source (setq auth-sources `((:source ,authinfo-file))) (setq gptel-api-key (auth-source-pick-first-password :host "api.openai.com")) - ;; (setq anthropic-api-key (auth-source-pick-first-password :host "api.anthropic.com")) + (setq anthropic-api-key (auth-source-pick-first-password :host "api.anthropic.com")) - ;; ;; Setup Anthropic's Claude - ;; (setq gptel-backend (gptel-make-anthropic "Claude" - ;; :stream t :key anthropic-api-key)) - ;; (setq gptel-model 'claude-3-opus-4-20250514) + ;; Setup Anthropic's Claude + (setq gptel-backend (gptel-make-anthropic "Claude" + :stream t :key anthropic-api-key)) + (setq gptel-model 'claude-3-opus-4-20250514) + ) ;; end use-package declaration - ) + +(with-eval-after-load 'projectile + (defun cj/gptel-add-file () + "Add a file to the GPTel context. +If inside a Projectile project, prompt from the project's file list; +otherwise use =read-file-name'." + (interactive) + (let* ((in-proj (and (fboundp 'projectile-project-p) + (projectile-project-p))) + (file (if in-proj + (projectile-completing-read + "GPTel add file: " + (projectile-current-project-files)) + (read-file-name "GPTel add file: ")))) + (gptel-add-file file))) + (define-key ai-keymap (kbd "f") #'cj/gptel-add-file)) ;; -------------------------------- GPTel-Magit -------------------------------- -- cgit v1.2.3