[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/gptel dade9ec8e1 231/273: gptel: Add introspection command
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/gptel dade9ec8e1 231/273: gptel: Add introspection commands |
Date: |
Wed, 1 May 2024 10:02:39 -0400 (EDT) |
branch: elpa/gptel
commit dade9ec8e1a8e129ce9530d3f48faa1504b6d8ad
Author: Karthik Chikmagalur <karthikchikmagalur@gmail.com>
Commit: Karthik Chikmagalur <karthikchikmagalur@gmail.com>
gptel: Add introspection commands
* gptel.el (gptel--inspect-query): Add a function to inspect the
query that will be sent. This is useful to ensure that (only and
all of) what you expect to be sent is being sent.
* gptel-transient.el (gptel-menu): Allow the query in progress to
be inspected from `gptel-menu` as an elisp or JSON object.
---
gptel-transient.el | 15 ++++++++++++++-
gptel.el | 25 +++++++++++++++++++++++++
2 files changed, 39 insertions(+), 1 deletion(-)
diff --git a/gptel-transient.el b/gptel-transient.el
index 971711c1a1..119c5ad93f 100644
--- a/gptel-transient.el
+++ b/gptel-transient.el
@@ -174,7 +174,20 @@ which see."
:if gptel--at-response-history-p
:transient t)
("E" "Ediff previous" gptel--ediff
- :if gptel--at-response-history-p)]]
+ :if gptel--at-response-history-p)]
+ ["Inspect"
+ ("I" "Query as Lisp"
+ (lambda ()
+ "Inspect the query that will be sent as a lisp object."
+ (interactive)
+ (gptel--sanitize-model)
+ (gptel--inspect-query)))
+ ("J" "Query as JSON"
+ (lambda ()
+ "Inspect the query that will be sent as a JSON object."
+ (interactive)
+ (gptel--sanitize-model)
+ (gptel--inspect-query 'json)))]]
(interactive)
(gptel--sanitize-model)
(transient-setup 'gptel-menu))
diff --git a/gptel.el b/gptel.el
index a75d905e82..bdf89d16e9 100644
--- a/gptel.el
+++ b/gptel.el
@@ -955,6 +955,31 @@ waiting for the response."
(gptel-request nil :stream gptel-stream)
(gptel--update-status " Waiting..." 'warning)))
+(declare-function json-pretty-print-buffer "json")
+(defun gptel--inspect-query (&optional arg)
+ "Show the full LLM query to be sent in a new buffer.
+
+This functions as a dry run of `gptel-send'. If prefix ARG is
+the symbol json, show the encoded JSON query instead of the lisp
+structure gptel uses."
+ (let* ((request-data
+ (gptel-request nil :stream gptel-stream :dry-run t)))
+ (with-current-buffer (get-buffer-create "*gptel-query*")
+ (let ((standard-output (current-buffer))
+ (inhibit-read-only t))
+ (buffer-disable-undo)
+ (erase-buffer)
+ (if (eq arg 'json)
+ (progn (fundamental-mode)
+ (insert (gptel--json-encode request-data))
+ (json-pretty-print-buffer))
+ (lisp-data-mode)
+ (prin1 request-data)
+ (pp-buffer))
+ (goto-char (point-min))
+ (view-mode 1)
+ (display-buffer (current-buffer) gptel-display-buffer-action)))))
+
(defun gptel--insert-response (response info)
"Insert the LLM RESPONSE into the gptel buffer.
- [nongnu] elpa/gptel 0ea3c7fb15 143/273: gptel-transient: Improve suffix message editor, (continued)
- [nongnu] elpa/gptel 0ea3c7fb15 143/273: gptel-transient: Improve suffix message editor, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel ce75072f9d 152/273: gptel: Bump version, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 3af2650342 170/273: gptel-transient: save window state when ediff, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel e67ed41e31 173/273: README: Specify: no key needed for llama backend, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 1fcb4606a2 184/273: Fix compilation warning in gptel-openai.el, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel b3d028d074 185/273: Add .gitignore, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 5465271541 207/273: gptel: Add gpt-4-0125-preview to model list (Fix #215), ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 43f625ecb9 209/273: gptel-openai: curl-args slot in gptel-backend (#221), ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel d502ad8ecb 222/273: test-gptel-org: Add markdown conversion tests, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 9925dc91b4 223/273: gptel: Improve markdown converter, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel dade9ec8e1 231/273: gptel: Add introspection commands,
ELPA Syncer <=
- [nongnu] elpa/gptel 7e6b106516 233/273: gptel-transient: Change menu display, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 26326c302e 249/273: gptel-anthropic: Parsing fix, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 22f7043c32 242/273: gptel: Fix gptel-end-of-response, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 94b13e78ec 239/273: gptel-transient: enable additional directive by default, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel f24ec164cd 251/273: gptel: Adjust doc-string, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 5d74ec4de0 254/273: gptel: Set system message correctly in gptel-request, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 53ee34653e 252/273: gptel-openai: Typo in gptel--json-read, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel f2fd2b13b0 257/273: gptel-org: Move response transform code for Org, ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel e994a443d3 262/273: README: add OpenRouter instructions (#282), ELPA Syncer, 2024/05/01
- [nongnu] elpa/gptel 7b6e3c5900 260/273: gptel: Release v0.8.5, ELPA Syncer, 2024/05/01