gptel-anthropic: Parsing fix

gptel-anthropic.el (gptel-curl--parse-stream): When parsing
responses from Anthropic, wait for more input when the
corresponding data chunk for the event hasn't arrived yet. (#261)
This commit is contained in:
Karthik Chikmagalur 2024-03-29 14:06:26 -07:00
parent 9a5a4a60d5
commit 26326c302e

View file

@ -45,6 +45,8 @@
(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)) (setq pt (match-beginning 0))
(if (equal (line-end-position) (point-max))
(error "Data block incomplete"))
(when (looking-at "content_block_\\(?:start\\|delta\\|stop\\)") (when (looking-at "content_block_\\(?:start\\|delta\\|stop\\)")
(forward-line 1) (forward-char 5) (forward-line 1) (forward-char 5)
(when-let* ((response (gptel--json-read)) (when-let* ((response (gptel--json-read))