gptel: Improve logging
* gptel.el (gptel--url-get-response): Log request headers as JSON objects. * gptel-curl.el (gptel-curl--get-args, gptel-curl--get-response): Log request headers as JSON objects, Curl command as a shell command you can copy and paste into the terminal.
This commit is contained in:
parent
f58ad9435c
commit
e18ceb1f84
2 changed files with 10 additions and 4 deletions
|
@ -64,7 +64,10 @@ PROMPTS is the data to send, TOKEN is a unique identifier."
|
||||||
(funcall header) header)))))
|
(funcall header) header)))))
|
||||||
(when gptel-log-level
|
(when gptel-log-level
|
||||||
(when (eq gptel-log-level 'debug)
|
(when (eq gptel-log-level 'debug)
|
||||||
(gptel--log (gptel--json-encode headers) "request headers"))
|
(gptel--log (gptel--json-encode
|
||||||
|
(mapcar (lambda (pair) (cons (intern (car pair)) (cdr pair)))
|
||||||
|
headers))
|
||||||
|
"request headers"))
|
||||||
(gptel--log data "request body"))
|
(gptel--log data "request body"))
|
||||||
(append
|
(append
|
||||||
gptel-curl--common-args
|
gptel-curl--common-args
|
||||||
|
@ -110,8 +113,8 @@ the response is inserted into the current buffer after point."
|
||||||
(process (apply #'start-process "gptel-curl"
|
(process (apply #'start-process "gptel-curl"
|
||||||
(generate-new-buffer "*gptel-curl*") "curl" args)))
|
(generate-new-buffer "*gptel-curl*") "curl" args)))
|
||||||
(when (eq gptel-log-level 'debug)
|
(when (eq gptel-log-level 'debug)
|
||||||
(gptel--log (gptel--json-encode (cons "curl" args))
|
(gptel--log (mapconcat #'shell-quote-argument (cons "curl" args) " \\\n")
|
||||||
"request Curl command"))
|
"request Curl command" 'no-json))
|
||||||
(with-current-buffer (process-buffer process)
|
(with-current-buffer (process-buffer process)
|
||||||
(set-process-query-on-exit-flag process nil)
|
(set-process-query-on-exit-flag process nil)
|
||||||
(setf (alist-get process gptel-curl--process-alist)
|
(setf (alist-get process gptel-curl--process-alist)
|
||||||
|
|
5
gptel.el
5
gptel.el
|
@ -1135,7 +1135,10 @@ the response is inserted into the current buffer after point."
|
||||||
'utf-8)))
|
'utf-8)))
|
||||||
(when gptel-log-level ;logging
|
(when gptel-log-level ;logging
|
||||||
(when (eq gptel-log-level 'debug)
|
(when (eq gptel-log-level 'debug)
|
||||||
(gptel--log (gptel--json-encode url-request-extra-headers) "request headers"))
|
(gptel--log (gptel--json-encode
|
||||||
|
(mapcar (lambda (pair) (cons (intern (car pair)) (cdr pair)))
|
||||||
|
url-request-extra-headers))
|
||||||
|
"request headers"))
|
||||||
(gptel--log url-request-data "request body"))
|
(gptel--log url-request-data "request body"))
|
||||||
(url-retrieve (let ((backend-url (gptel-backend-url gptel-backend)))
|
(url-retrieve (let ((backend-url (gptel-backend-url gptel-backend)))
|
||||||
(if (functionp backend-url)
|
(if (functionp backend-url)
|
||||||
|
|
Loading…
Add table
Reference in a new issue