|
89 | 89 | :content `[(:type "text" :text ,text)])))
|
90 | 90 |
|
91 | 91 | (cl-defmethod gptel--parse-buffer ((_backend gptel-anthropic) &optional max-entries)
|
92 |
| - (let ((prompts) (prop) |
| 92 | + (let ((prompts) (prop) (prev-pt (point)) |
93 | 93 | (include-media (and gptel-track-media (or (gptel--model-capable-p 'media)
|
94 | 94 | (gptel--model-capable-p 'url)))))
|
95 | 95 | (if (or gptel-mode gptel-track-response)
|
|
103 | 103 | ;; HACK Until we can find a more robust solution for editing
|
104 | 104 | ;; responses, ignore prompts containing only whitespace, as the
|
105 | 105 | ;; 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 |
109 | 110 | (push (list :role "assistant"
|
110 | 111 | :content
|
111 | 112 | (buffer-substring-no-properties (prop-match-beginning prop)
|
112 | 113 | (prop-match-end prop)))
|
113 |
| - prompts)) |
114 |
| - (unless (save-excursion (skip-syntax-forward " ") |
115 |
| - (eq (get-char-property (point) 'gptel) 'response)) |
| 114 | + prompts) |
116 | 115 | (if include-media ; user role: possibly with media
|
117 | 116 | (push (list :role "user"
|
118 | 117 | :content
|
|
126 | 125 | (buffer-substring-no-properties (prop-match-beginning prop)
|
127 | 126 | (prop-match-end prop))))
|
128 | 127 | prompts))))
|
| 128 | + (setq prev-pt (point)) |
129 | 129 | (and max-entries (cl-decf max-entries)))
|
130 | 130 | (push (list :role "user"
|
131 | 131 | :content
|
|
0 commit comments