Skip to content

Commit 1b6c36c

Browse files
committed
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.
1 parent 0a8917a commit 1b6c36c

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

gptel-anthropic.el

+7-7
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
:content `[(:type "text" :text ,text)])))
9090

9191
(cl-defmethod gptel--parse-buffer ((_backend gptel-anthropic) &optional max-entries)
92-
(let ((prompts) (prop)
92+
(let ((prompts) (prop) (prev-pt (point))
9393
(include-media (and gptel-track-media (or (gptel--model-capable-p 'media)
9494
(gptel--model-capable-p 'url)))))
9595
(if (or gptel-mode gptel-track-response)
@@ -103,16 +103,15 @@
103103
;; HACK Until we can find a more robust solution for editing
104104
;; responses, ignore prompts containing only whitespace, as the
105105
;; Anthropic API can't handle it. See #452, #409, #406, #351 and #321
106-
(if (prop-match-value prop) ; assistant role
107-
(unless (save-excursion (skip-syntax-forward " ")
108-
(null (get-char-property (point) 'gptel)))
106+
;; We check for blank prompts by skipping whitespace and comparing
107+
;; point against the previous.
108+
(unless (save-excursion (skip-syntax-forward " ") (>= (point) prev-pt))
109+
(if (prop-match-value prop) ; assistant role
109110
(push (list :role "assistant"
110111
:content
111112
(buffer-substring-no-properties (prop-match-beginning prop)
112113
(prop-match-end prop)))
113-
prompts))
114-
(unless (save-excursion (skip-syntax-forward " ")
115-
(eq (get-char-property (point) 'gptel) 'response))
114+
prompts)
116115
(if include-media ; user role: possibly with media
117116
(push (list :role "user"
118117
:content
@@ -126,6 +125,7 @@
126125
(buffer-substring-no-properties (prop-match-beginning prop)
127126
(prop-match-end prop))))
128127
prompts))))
128+
(setq prev-pt (point))
129129
(and max-entries (cl-decf max-entries)))
130130
(push (list :role "user"
131131
:content

0 commit comments

Comments
 (0)