branch: elpa/gptel commit fc9381219654f81992e13c6a52355254c578a60c Author: Karthik Chikmagalur <karthikchikmaga...@gmail.com> Commit: Karthik Chikmagalur <karthikchikmaga...@gmail.com>
gptel: Don't run callback if response is empty * gptel.el (gptel--url-get-response): In the non-streaming case, if the response is nil but the request is successful (HTTP 100/200), don't run the callback. This is because, according to the `gptel-request' API, the callback interprets a nil response argument as an error. This is a valid response, and can happen when the LLM calls a tool, for instance. Streaming responses are already handled correctly. * gptel-curl.el (gptel-curl--sentinel): Ditto. --- gptel-curl.el | 5 +++-- gptel.el | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/gptel-curl.el b/gptel-curl.el index b3ba128c82..5021182748 100644 --- a/gptel-curl.el +++ b/gptel-curl.el @@ -326,8 +326,9 @@ PROCESS and _STATUS are process parameters." (plist-put proc-info :status http-msg) (gptel--fsm-transition fsm) ;WAIT -> TYPE (when error (plist-put proc-info :error error)) - (with-demoted-errors "gptel callback error: %S" - (funcall proc-callback response proc-info))) + (when (or response (not (member http-status '("200" "100")))) + (with-demoted-errors "gptel callback error: %S" + (funcall proc-callback response proc-info)))) (gptel--fsm-transition fsm)) ;TYPE -> next (setf (alist-get process gptel--request-alist nil 'remove) nil) (kill-buffer proc-buf))) diff --git a/gptel.el b/gptel.el index 7ce9b9042d..ae2267348e 100644 --- a/gptel.el +++ b/gptel.el @@ -2551,8 +2551,9 @@ the response is inserted into the current buffer after point." (plist-put info :status http-msg) (gptel--fsm-transition fsm) ;WAIT -> TYPE (when error (plist-put info :error error)) - (with-demoted-errors "gptel callback error: %S" - (funcall callback response info)) + (when (or response (not (member http-status '("200" "100")))) + (with-demoted-errors "gptel callback error: %S" + (funcall callback response info))) (gptel--fsm-transition fsm) ;TYPE -> next (setf (alist-get buf gptel--request-alist nil 'remove) nil) (kill-buffer buf)))