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

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

[nongnu] elpa/gptel 1b6c36c519: gptel-anthropic: Retry: blank response r


From: ELPA Syncer
Subject: [nongnu] elpa/gptel 1b6c36c519: gptel-anthropic: Retry: blank response regions (#452)
Date: Sun, 8 Dec 2024 19:00:17 -0500 (EST)

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

    gptel-anthropic: Retry: blank response regions (#452)
    
    * gptel-anthropic.el (gptel--parse-buffer): Following from the
    previous approach, change how we guard against blank response
    regions (#452, #409, #406, #351, #321).  This time we compare the
    current and previous values of (point), after skipping whitespace,
    when parsing the buffer and constructing the prompt.
---
 gptel-anthropic.el | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/gptel-anthropic.el b/gptel-anthropic.el
index 91b797d620..4128e8dd10 100644
--- a/gptel-anthropic.el
+++ b/gptel-anthropic.el
@@ -89,7 +89,7 @@
                  :content `[(:type "text" :text ,text)])))
 
 (cl-defmethod gptel--parse-buffer ((_backend gptel-anthropic) &optional 
max-entries)
-  (let ((prompts) (prop)
+  (let ((prompts) (prop) (prev-pt (point))
         (include-media (and gptel-track-media (or (gptel--model-capable-p 
'media)
                                                 (gptel--model-capable-p 
'url)))))
     (if (or gptel-mode gptel-track-response)
@@ -103,16 +103,15 @@
           ;; HACK Until we can find a more robust solution for editing
           ;; responses, ignore prompts containing only whitespace, as the
           ;; Anthropic API can't handle it.  See #452, #409, #406, #351 and 
#321
-          (if (prop-match-value prop)   ; assistant role
-              (unless (save-excursion (skip-syntax-forward " ")
-                                      (null (get-char-property (point) 
'gptel)))
+          ;; We check for blank prompts by skipping whitespace and comparing
+          ;; point against the previous.
+          (unless (save-excursion (skip-syntax-forward " ") (>= (point) 
prev-pt))
+            (if (prop-match-value prop) ; assistant role
                 (push (list :role "assistant"
                             :content
                             (buffer-substring-no-properties 
(prop-match-beginning prop)
                                                             (prop-match-end 
prop)))
-                      prompts))
-            (unless (save-excursion (skip-syntax-forward " ")
-                                    (eq (get-char-property (point) 'gptel) 
'response))
+                      prompts)
               (if include-media         ; user role: possibly with media
                   (push (list :role "user"
                               :content
@@ -126,6 +125,7 @@
                              (buffer-substring-no-properties 
(prop-match-beginning prop)
                                                              (prop-match-end 
prop))))
                       prompts))))
+          (setq prev-pt (point))
           (and max-entries (cl-decf max-entries)))
       (push (list :role "user"
                   :content



reply via email to

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