gptel-anthropic: Handle missing response chunks (trial)
gptel-anthropic.el (gptel-curl--parse-stream): Reset point explicitly when parsing streaming responses returned by the Anthropic API. Try to address #233.
This commit is contained in:
parent
199595b0c8
commit
2487ada4d6
1 changed files with 4 additions and 3 deletions
|
@ -41,9 +41,11 @@
|
||||||
|
|
||||||
(cl-defmethod gptel-curl--parse-stream ((_backend gptel-anthropic) _info)
|
(cl-defmethod gptel-curl--parse-stream ((_backend gptel-anthropic) _info)
|
||||||
(let* ((json-object-type 'plist)
|
(let* ((json-object-type 'plist)
|
||||||
(content-strs))
|
(content-strs)
|
||||||
|
(pt (point)))
|
||||||
(condition-case nil
|
(condition-case nil
|
||||||
(while (re-search-forward "^event: " nil t)
|
(while (re-search-forward "^event: " nil t)
|
||||||
|
(setq pt (match-beginning 0))
|
||||||
(cond
|
(cond
|
||||||
((looking-at "content_block_\\(?:start\\|delta\\|stop\\)")
|
((looking-at "content_block_\\(?:start\\|delta\\|stop\\)")
|
||||||
(save-match-data
|
(save-match-data
|
||||||
|
@ -52,8 +54,7 @@
|
||||||
(content (map-nested-elt
|
(content (map-nested-elt
|
||||||
response '(:delta :text))))
|
response '(:delta :text))))
|
||||||
(push content content-strs))))))
|
(push content content-strs))))))
|
||||||
(error
|
(error (goto-char pt)))
|
||||||
(goto-char (match-beginning 0))))
|
|
||||||
(apply #'concat (nreverse content-strs))))
|
(apply #'concat (nreverse content-strs))))
|
||||||
|
|
||||||
(cl-defmethod gptel--parse-response ((_backend gptel-anthropic) response _info)
|
(cl-defmethod gptel--parse-response ((_backend gptel-anthropic) response _info)
|
||||||
|
|
Loading…
Add table
Reference in a new issue