emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/gptel ffed97d2e4 05/11: gptel: Adjust persistence for dyna


From: ELPA Syncer
Subject: [nongnu] elpa/gptel ffed97d2e4 05/11: gptel: Adjust persistence for dynamic directives
Date: Sat, 30 Nov 2024 07:00:04 -0500 (EST)

branch: elpa/gptel
commit ffed97d2e4f5a74d2e2cf6a7216b06192ed60f1f
Author: Karthik Chikmagalur <karthikchikmagalur@gmail.com>
Commit: Karthik Chikmagalur <karthikchikmagalur@gmail.com>

    gptel: Adjust persistence for dynamic directives
    
    * gptel.el (gptel--save-state): When saving state, save the static
    value of the active gptel directive.  This means dynamic
    directives will be evaluated, and only the system message part of
    directives that are templated conversations will be saved to the
    file.
    
    It's not clear yet how to correctly persist dynamic directives.
    This limitation may be addressed in the future.
    
    * gptel-org.el (gptel-org-set-properties): Similar adjustments for
    Org mode chat buffers.
---
 gptel-org.el | 6 +++++-
 gptel.el     | 6 ++++--
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/gptel-org.el b/gptel-org.el
index 90260fbeb9..1888e8ad0c 100644
--- a/gptel-org.el
+++ b/gptel-org.el
@@ -49,6 +49,7 @@
 (declare-function gptel--get-buffer-bounds "gptel")
 (declare-function gptel-backend-name "gptel")
 (declare-function gptel--parse-buffer "gptel")
+(declare-function gptel--parse-directive "gptel")
 (declare-function org-entry-get "org")
 (declare-function org-entry-put "org")
 (declare-function org-with-wide-buffer "org-macs")
@@ -395,7 +396,10 @@ non-nil (default), display a message afterwards."
     (org-entry-put pt "GPTEL_NUM_MESSAGES_TO_SEND"
                    (number-to-string gptel--num-messages-to-send)))
   (org-entry-put pt "GPTEL_SYSTEM"
-                 (string-replace "\n" "\\n" gptel--system-message))
+                 (and-let* ((msg (car-safe
+                                  (gptel--parse-directive
+                                   gptel--system-message))))
+                   (string-replace "\n" "\\n" msg)))
   (when gptel-max-tokens
     (org-entry-put
      pt "GPTEL_MAX_TOKENS" (number-to-string gptel-max-tokens)))
diff --git a/gptel.el b/gptel.el
index 21c097e7b6..599d5b8929 100644
--- a/gptel.el
+++ b/gptel.el
@@ -1107,9 +1107,11 @@ file."
                                    (gptel-backend-name gptel-backend))
           (unless (equal (default-value 'gptel-temperature) gptel-temperature)
             (add-file-local-variable 'gptel-temperature gptel-temperature))
-          (unless (string= (default-value 'gptel--system-message)
+          (unless (equal (default-value 'gptel--system-message)
                            gptel--system-message)
-            (add-file-local-variable 'gptel--system-message 
gptel--system-message))
+            (add-file-local-variable
+             'gptel--system-message
+             (car-safe (gptel--parse-directive gptel--system-message))))
           (when gptel-max-tokens
             (add-file-local-variable 'gptel-max-tokens gptel-max-tokens))
           (when (natnump gptel--num-messages-to-send)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]