branch: externals/llm
commit fa6c4452711495ea2854f10dc82f43c4f22707c5
Author: Andrew Hyatt <ahy...@gmail.com>
Commit: Andrew Hyatt <ahy...@gmail.com>

    Fix issue with not handline the plz response correctly for streaming
    
    This issue was brought up in https://github.com/ahyatt/llm/pull/35
---
 llm-request-plz.el | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/llm-request-plz.el b/llm-request-plz.el
index 0287aceaea..1342f47ebb 100644
--- a/llm-request-plz.el
+++ b/llm-request-plz.el
@@ -149,10 +149,17 @@ the buffer is turned into JSON and passed to ON-SUCCESS."
     :headers (append headers
                      '(("Content-Type" . "application/json")))
     :then (lambda (response)
-            (when on-success-raw
-              (funcall on-success-raw response))
-            (when on-success
-              (funcall on-success (json-read-from-string response))))
+            ;; Media types can return a response object sometimes, otherwise it
+            ;; is a string.  This is normal, since this is dependent on the
+            ;; `:as' argument.
+            (let ((response (if (plz-response-p response)
+                                (plz-response-body response)
+                              response)))
+              (when on-success-raw
+                (funcall on-success-raw response))
+              (when on-success
+                (funcall on-success (when (and response (> (length response) 
0))
+                                      (json-read-from-string response))))))
     :else (lambda (error)
             (when on-error
               (llm-request-plz--handle-error error on-error)))

Reply via email to