diff --git a/gptel-org.el b/gptel-org.el index f9a6b17c..9c4d7be8 100644 --- a/gptel-org.el +++ b/gptel-org.el @@ -41,6 +41,7 @@ (defvar org-link-angle-re) (defvar org-link-bracket-re) (declare-function mailcap-file-name-to-mime-type "mailcap") +(declare-function org-attach-expand "org-attach") (declare-function gptel--model-capable-p "gptel") (declare-function gptel--model-mime-capable-p "gptel") (declare-function gptel--model-name "gptel") @@ -365,8 +366,11 @@ for inclusion into the user prompt for the gptel request." (when-let* ((link (org-element-context)) ((gptel-org--link-standalone-p link)) (raw-link (org-element-property :raw-link link)) - (path (org-element-property :path link)) + (raw-path (org-element-property :path link)) (type (org-element-property :type link)) + (path (if (string= type "attachment") + (org-attach-expand raw-path) + raw-path)) ;; FIXME This is not a good place to check for url capability! ((member type `("attachment" "file" ,@(and (gptel--model-capable-p 'url) diff --git a/gptel-request.el b/gptel-request.el index fded267d..22ea5ad8 100644 --- a/gptel-request.el +++ b/gptel-request.el @@ -2033,9 +2033,12 @@ Initiate the request when done." (save-excursion (goto-char (point-min)) (gptel--parse-list-and-insert (cdr directive)))) (goto-char (point-max)) - (setq full-prompt (gptel--parse-buffer ;prompt from buffer or explicitly supplied - gptel-backend (and gptel--num-messages-to-send - (* 2 gptel--num-messages-to-send)))) + ;; Parse buffer in original buffer context so org-attach-expand can access + ;; Org properties (ID, ATTACH_DIR) not present in the temp copy buffer + (setq full-prompt (with-current-buffer (plist-get info :buffer) + (gptel--parse-buffer ;prompt from buffer or explicitly supplied + gptel-backend (and gptel--num-messages-to-send + (* 2 gptel--num-messages-to-send))))) ;; Inject media chunks into the first user prompt if required. Media ;; chunks are always included with the first user message, ;; irrespective of the preference in `gptel-use-context'. This is