Skip to content

Commit

Permalink
gptel-anthropic: Guard against blank response regions (#452)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
karthink committed Dec 8, 2024
1 parent ba07a52 commit 983a9df
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions gptel-anthropic.el
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,17 @@
(when (get-char-property (max (point-min) (1- (point)))
'gptel)
t))))
;; 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
(push (list :role "assistant"
:content
(buffer-substring-no-properties (prop-match-beginning prop)
(prop-match-end prop)))
prompts)
;; HACK Until we can find a more robust solution for editing
;; responses, ignore user prompts containing only whitespace, as the
;; Anthropic API can't handle it. See #409, #406, #351 and #321
(unless (save-excursion (skip-syntax-forward " ")
(null (get-char-property (point) 'gptel)))
(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))
(if include-media ; user role: possibly with media
Expand Down

0 comments on commit 983a9df

Please sign in to comment.