branch: elpa/gptel
commit 11fbb4dcd9e634af2e42784d0cf2af840c5e9468
Author: Karthik Chikmagalur <karthikchikmaga...@gmail.com>
Commit: Karthik Chikmagalur <karthikchikmaga...@gmail.com>

    gptel: Ignore non-streaming blank responses
    
    If the non-streaming response is all whitespace, do not call the
    gptel-request callback.  This causes `gptel-response-separator' to
    be inserted without any text preceding it. (#819)
    
    Note that prior to this commit, we string-trimmed responses
    already, so whitespace at the beginning and ends of responses was
    not respected.  Blank responses were thus passed as empty strings
    to the callbacks.  As of this commit, blank responses are not sent
    to the callback at all.
    
    If it turns out that blank responses are significant for special
    tasks/gptel-request callbacks, we can move this check to the
    default callback, `gptel--insert-response' and call the callback
    with blank responses.
    
    * gptel.el (gptel--url-parse-response): Make the change.
    
    * gptel-curl.el (gptel-curl--parse-response): Make the change.
---
 gptel-curl.el | 6 +++---
 gptel.el      | 3 ++-
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/gptel-curl.el b/gptel-curl.el
index 2d39a2b64c..e2d6f54ddb 100644
--- a/gptel-curl.el
+++ b/gptel-curl.el
@@ -441,9 +441,9 @@ PROC-INFO is a plist with contextual information."
           (cond
            ;; FIXME Handle the case where HTTP 100 is followed by HTTP (not 
200) BUG #194
            ((member http-status '("200" "100"))
-            (list (and-let* ((resp ;; (funcall parser nil response proc-info)
-                              (gptel--parse-response (plist-get proc-info 
:backend)
-                                                     response proc-info)))
+            (list (and-let* ((resp (gptel--parse-response
+                                    (plist-get proc-info :backend) response 
proc-info))
+                             ((not (string-blank-p resp))))
                     (string-trim resp))
                   http-status http-msg))
            ((plist-get response :error)
diff --git a/gptel.el b/gptel.el
index 0115e7fea3..2412dc82d4 100644
--- a/gptel.el
+++ b/gptel.el
@@ -2865,7 +2865,8 @@ See `gptel-curl--get-response' for its contents.")
        ;; FIXME Handle the case where HTTP 100 is followed by HTTP (not 200) 
BUG #194
        ((or (memq url-http-response-status '(200 100))
             (string-match-p "\\(?:1\\|2\\)00 OK" http-msg))
-        (list (and-let* ((resp (gptel--parse-response backend response 
proc-info)))
+        (list (and-let* ((resp (gptel--parse-response backend response 
proc-info))
+                         ((not (string-blank-p resp))))
                 (string-trim resp))
               http-status http-msg))
        ((plist-get response :error)

Reply via email to