[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/gptel a32f4effe5 215/273: gptel-curl: Handle empty respons
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/gptel a32f4effe5 215/273: gptel-curl: Handle empty responses correctly |
Date: |
Wed, 1 May 2024 10:02:25 -0400 (EDT) |
branch: elpa/gptel
commit a32f4effe5bb659d986cb376a48400db07820202
Author: Karthik Chikmagalur <karthikchikmagalur@gmail.com>
Commit: Karthik Chikmagalur <karthikchikmagalur@gmail.com>
gptel-curl: Handle empty responses correctly
gptel-curl.el (gptel-curl--stream-cleanup): The LLM response can
be empty with HTTP status 200, for example when the API responds
with an error description instead. Handle this case gracefully.
When `gptel-mode` is enabled, also inform the user that the
response was empty. Fix #234.
gptel.el (gptel-post-response-functions): Documentation. Explain
the arguments passed to each hook function in this hook when the
response fails or is empty.
---
gptel-curl.el | 27 +++++++++++++--------------
gptel.el | 4 +++-
2 files changed, 16 insertions(+), 15 deletions(-)
diff --git a/gptel-curl.el b/gptel-curl.el
index bb7fc39a49..4c4215a831 100644
--- a/gptel-curl.el
+++ b/gptel-curl.el
@@ -199,20 +199,17 @@ PROCESS and _STATUS are process parameters."
(tracking-marker (plist-get info :tracking-marker))
(start-marker (plist-get info :position))
(http-status (plist-get info :http-status))
- (http-msg (plist-get info :status))
- response-beg response-end)
+ (http-msg (plist-get info :status)))
(when gptel-log-level (gptel-curl--log-response proc-buf info)) ;logging
- (if (equal http-status "200")
- (progn
- ;; Finish handling response
- (with-current-buffer (marker-buffer start-marker)
- (setq response-beg (marker-position start-marker)
- response-end (marker-position tracking-marker))
- (pulse-momentary-highlight-region response-beg tracking-marker)
- (when gptel-mode (save-excursion (goto-char tracking-marker)
- (insert "\n\n"
(gptel-prompt-prefix-string)))))
- (with-current-buffer gptel-buffer
- (when gptel-mode (gptel--update-status " Ready" 'success))))
+ (if (equal http-status "200") ;Finish
handling response
+ (with-current-buffer gptel-buffer
+ (if (not tracking-marker) ;Empty response
+ (when gptel-mode (gptel--update-status " Empty response"
'success))
+ (pulse-momentary-highlight-region start-marker tracking-marker)
+ (when gptel-mode
+ (save-excursion (goto-char tracking-marker)
+ (insert "\n\n" (gptel-prompt-prefix-string)))
+ (gptel--update-status " Ready" 'success))))
;; Or Capture error message
(with-current-buffer proc-buf
(goto-char (point-max))
@@ -240,7 +237,9 @@ PROCESS and _STATUS are process parameters."
(gptel--update-status
(format " Response Error: %s" http-msg) 'error))))
(with-current-buffer gptel-buffer
- (run-hook-with-args 'gptel-post-response-functions response-beg
response-end)))
+ (run-hook-with-args 'gptel-post-response-functions
+ (marker-position start-marker)
+ (marker-position (or tracking-marker
start-marker)))))
(setf (alist-get process gptel-curl--process-alist nil 'remove) nil)
(kill-buffer proc-buf)))
diff --git a/gptel.el b/gptel.el
index 2b9cce7990..2cc360e9b1 100644
--- a/gptel.el
+++ b/gptel.el
@@ -250,7 +250,9 @@ to the LLM, and after the full response has been inserted.
Each
function is called with two arguments: the response beginning and
end positions.
-Note: this hook runs even if the request fails."
+Note: this hook runs even if the request fails. In this case the
+response beginning and end positions are both the cursor position
+at the time of the request."
:group 'gptel
:type 'hook)
- [nongnu] elpa/gptel 3e361323d5 137/273: Update available OpenAI GPT models to match API (#146), (continued)
- [nongnu] elpa/gptel 3e361323d5 137/273: Update available OpenAI GPT models to match API (#146), ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 32dd463bd6 160/273: README: Mention YouTube demo, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 3ac5963080 168/273: README: Add instructions for Llamafile, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel bea31e33e2 175/273: gptel-ollama: Use default host in gptel-make-ollama, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel c6a07043af 179/273: gptel-kagi: Add support for Kagi FastGPT, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 3fb064a763 181/273: gptel: Better handling of read-only bufs, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel e79e386964 191/273: README: Move gptel-request to FAQ, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel a61fda4661 197/273: gptel-transient: better multi-line directive editing, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 226f8f0d90 208/273: gptel: Add customizable display-action (#216), ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 8ba07d042c 210/273: gptel: Bump version, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel a32f4effe5 215/273: gptel-curl: Handle empty responses correctly,
ELPA Syncer <=
- [nongnu] elpa/gptel e5f54d1d09 229/273: gptel-anthropic: Modify order of request items, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel f529457bbe 232/273: gptel: Use visual-line-mode when ediff-ing, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 9eea4be5ed 245/273: gptel-transient: Fix gptel-menu definition bug (#265), ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 6d3e4a99f5 236/273: gptel-transient: Rename additional-directive functions, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 5d069cfca8 243/273: gptel-anthropic: Simplify stream parser, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel b31c9be5e0 238/273: gptel-ollama: Adjust Ollama stream parser for libjansson, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 73a0cc25ba 237/273: gptel-transient: Simplify model selection, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 12e00cbd09 247/273: gptel-transient: No pre-fill when reading from minibuffer, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 5dcbf40066 241/273: gptel: Make model parameters global, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 567af4d2ee 258/273: gptel-org: Read config from Org properties (#141), ELPA Syncer, 2024/05/01