emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/gptel 2487ada4d6 217/273: gptel-anthropic: Handle missing


From: ELPA Syncer
Subject: [nongnu] elpa/gptel 2487ada4d6 217/273: gptel-anthropic: Handle missing response chunks (trial)
Date: Wed, 1 May 2024 10:02:28 -0400 (EDT)

branch: elpa/gptel
commit 2487ada4d659fe9ef4129a876178a99204bffcb0
Author: Karthik Chikmagalur <karthikchikmagalur@gmail.com>
Commit: Karthik Chikmagalur <karthikchikmagalur@gmail.com>

    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.
---
 gptel-anthropic.el | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/gptel-anthropic.el b/gptel-anthropic.el
index c742c7fd7b..fa0aed0b69 100644
--- a/gptel-anthropic.el
+++ b/gptel-anthropic.el
@@ -41,9 +41,11 @@
 
 (cl-defmethod gptel-curl--parse-stream ((_backend gptel-anthropic) _info)
   (let* ((json-object-type 'plist)
-         (content-strs))
+         (content-strs)
+         (pt (point)))
     (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
@@ -52,8 +54,7 @@
                           (content (map-nested-elt
                                     response '(:delta :text))))
                 (push content content-strs))))))
-      (error
-       (goto-char (match-beginning 0))))
+      (error (goto-char pt)))
     (apply #'concat (nreverse content-strs))))
 
 (cl-defmethod gptel--parse-response ((_backend gptel-anthropic) response _info)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]