From 5d069cfca8b3b93d3601da6a4d71da7735d9e479 Mon Sep 17 00:00:00 2001 From: Karthik Chikmagalur Date: Tue, 19 Mar 2024 18:01:55 -0700 Subject: [PATCH] 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. --- gptel-anthropic.el | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/gptel-anthropic.el b/gptel-anthropic.el index 8d742af..895761c 100644 --- a/gptel-anthropic.el +++ b/gptel-anthropic.el @@ -45,14 +45,12 @@ (condition-case nil (while (re-search-forward "^event: " nil t) (setq pt (match-beginning 0)) - (cond - ((looking-at "content_block_\\(?:start\\|delta\\|stop\\)") - (save-match-data - (forward-line 1) (forward-char 5) - (when-let* ((response (gptel--json-read)) - (content (map-nested-elt - response '(:delta :text)))) - (push content content-strs)))))) + (when (looking-at "content_block_\\(?:start\\|delta\\|stop\\)") + (forward-line 1) (forward-char 5) + (when-let* ((response (gptel--json-read)) + (content (map-nested-elt + response '(:delta :text)))) + (push content content-strs)))) (error (goto-char pt))) (apply #'concat (nreverse content-strs))))