branch: elpa/gptel
commit 3a4663a5889be9beb2d8e67666c1a9c074330455
Author: Karthik Chikmagalur <[email protected]>
Commit: Karthik Chikmagalur <[email protected]>
gptel-transient: Omit tool results when not sending to buffer
* gptel-transient.el (gptel--suffix-send): Omit tool call results
when the output is redirected to the kill ring or echo area. The
output is very noisy otherwise. When sending the response to the
kill ring, accumulate all output around possible tool calls first.
* NEWS: Mention change.
---
NEWS | 13 +++++++++++++
gptel-transient.el | 26 +++++++++++++++-----------
2 files changed, 28 insertions(+), 11 deletions(-)
diff --git a/NEWS b/NEWS
index d4cd1177829..78df4b186f4 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,18 @@
# -*- mode: org; -*-
+* 0.9.9.5-pre
+
+** Breaking changes
+
+** New models and backends
+
+** New features and UI changes
+
+- When redirecting LLM responses to the kill ring or echo area, gptel
+ now omits tool call results, as these tend to be very noisy. Kill
+ ring redirection now correctly captures the full response from the
+ LLM, including pre- and post-tool-call text.
+
* 0.9.9.3
** Breaking changes
diff --git a/gptel-transient.el b/gptel-transient.el
index a2f86953105..be1bd441ddc 100644
--- a/gptel-transient.el
+++ b/gptel-transient.el
@@ -1632,7 +1632,6 @@ This sets the variable `gptel-include-tool-results',
which see."
(pcase resp
((pred stringp) (message "%s response: %s" backend-name resp))
(`(tool-call . ,tool-calls) (gptel--display-tool-calls
tool-calls info 'minibuffer))
- (`(tool-result . ,tool-results) (gptel--display-tool-results
tool-results info))
(_ (when (and (null resp) (plist-get info :error))
(message "%s response error: %s"
backend-name (plist-get info :status))))))))
@@ -1640,16 +1639,21 @@ This sets the variable `gptel-include-tool-results',
which see."
(setq redirect-output t)
(setq stream nil)
(setq callback
- (lambda (resp info &optional _raw)
- (pcase resp
- ((pred stringp) (kill-new resp)
- (message "%s response: \"%s\" copied to kill-ring."
backend-name
- (truncate-string-to-width resp 30)))
- (`(tool-call . ,tool-calls) (gptel--display-tool-calls
tool-calls info 'minibuffer))
- (`(tool-result . ,tool-results) (gptel--display-tool-results
tool-results info))
- (_ (when (and (null resp) (plist-get info :error))
- (message "%s response error: %s" backend-name
- (plist-get info :status))))))))
+ (let ((accum))
+ (lambda (resp info &optional _raw)
+ (pcase resp
+ ((pred stringp) (push resp accum)
+ (unless (plist-get info :tool-use)
+ (kill-new (apply #'concat (nreverse accum)))
+ (message "%s response: \"%s\" copied to kill-ring."
backend-name
+ (truncate-string-to-width resp 30 nil nil t))))
+ (`(tool-call . ,tool-calls) (gptel--display-tool-calls
tool-calls info 'minibuffer))
+ (_ (when (and (null resp) (plist-get info :error))
+ (if accum (kill-new (apply #'concat (nreverse accum))))
+ (message
+ (concat "%s response error: %s."
+ (and accum " Partial response copied to
kill-ring."))
+ backend-name (plist-get info :status)))))))))
((setq gptel-buffer-name
(cl-some (lambda (s) (and (stringp s) (string-prefix-p "g" s)
(substring s 1)))