Skip to content

Commit 983a9df

Browse files
committed
gptel-anthropic: Guard against blank response regions (#452)
* gptel-anthropic.el (gptel--parse-buffer): Guard against response regions that are whitespace-only (#452, #409, #406, #351, #321). This is an Anthropic-API specific problem. Eventually this will need to be fixed more robustly, using rear-sticky text properties.
1 parent ba07a52 commit 983a9df

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

gptel-anthropic.el

+10-8
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,17 @@
100100
(when (get-char-property (max (point-min) (1- (point)))
101101
'gptel)
102102
t))))
103+
;; HACK Until we can find a more robust solution for editing
104+
;; responses, ignore prompts containing only whitespace, as the
105+
;; Anthropic API can't handle it. See #452, #409, #406, #351 and #321
103106
(if (prop-match-value prop) ; assistant role
104-
(push (list :role "assistant"
105-
:content
106-
(buffer-substring-no-properties (prop-match-beginning prop)
107-
(prop-match-end prop)))
108-
prompts)
109-
;; HACK Until we can find a more robust solution for editing
110-
;; responses, ignore user prompts containing only whitespace, as the
111-
;; Anthropic API can't handle it. See #409, #406, #351 and #321
107+
(unless (save-excursion (skip-syntax-forward " ")
108+
(null (get-char-property (point) 'gptel)))
109+
(push (list :role "assistant"
110+
:content
111+
(buffer-substring-no-properties (prop-match-beginning prop)
112+
(prop-match-end prop)))
113+
prompts))
112114
(unless (save-excursion (skip-syntax-forward " ")
113115
(eq (get-char-property (point) 'gptel) 'response))
114116
(if include-media ; user role: possibly with media

0 commit comments

Comments
 (0)