[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/gptel 983a9dfbf8 1/2: gptel-anthropic: Guard against blank
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/gptel 983a9dfbf8 1/2: gptel-anthropic: Guard against blank response regions (#452) |
Date: |
Sat, 7 Dec 2024 22:00:18 -0500 (EST) |
branch: elpa/gptel
commit 983a9dfbf87f526efe2cfcf8a749f51ce466beaa
Author: Karthik Chikmagalur <karthikchikmagalur@gmail.com>
Commit: Karthik Chikmagalur <karthikchikmagalur@gmail.com>
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.
---
gptel-anthropic.el | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/gptel-anthropic.el b/gptel-anthropic.el
index cfe00c0213..91b797d620 100644
--- a/gptel-anthropic.el
+++ b/gptel-anthropic.el
@@ -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