Skip to content

Commit

Permalink
gptel-anthropic: Retry: blank response regions (#452)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
karthink committed Dec 8, 2024
1 parent 0a8917a commit 1b6c36c
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions gptel-anthropic.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 1b6c36c

Please sign in to comment.