gptel-anthropic: Simplify stream parser

* gptel-anthropic.el (gptel-curl--parse-stream): Remove extraneous
statements and simplify the stream parser.  Addresses #261, but
the main problem is still elusive.
This commit is contained in:
Karthik Chikmagalur 2024-03-19 18:01:55 -07:00
parent 22f7043c32
commit 5d069cfca8

View file

@ -45,14 +45,12 @@
(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))
(cond (when (looking-at "content_block_\\(?:start\\|delta\\|stop\\)")
((looking-at "content_block_\\(?:start\\|delta\\|stop\\)")
(save-match-data
(forward-line 1) (forward-char 5) (forward-line 1) (forward-char 5)
(when-let* ((response (gptel--json-read)) (when-let* ((response (gptel--json-read))
(content (map-nested-elt (content (map-nested-elt
response '(:delta :text)))) response '(:delta :text))))
(push content content-strs)))))) (push content content-strs))))
(error (goto-char pt))) (error (goto-char pt)))
(apply #'concat (nreverse content-strs)))) (apply #'concat (nreverse content-strs))))