gptel: Rename stream-related vars and defuns
* gptel.el (gptel--convert-playback-markdown->org, gptel--request-data, gptel-playback): - `gptel-playback' is now obsolete, use `gptel-stream' instead. - `gptel--convert-playback-markdown->org': rename to `gptel--stream-convert-markdown->org' * gptel-curl.el (gptel-curl--filter, gptel-curl-get-response): - `gptel--insert-response-stream': rename to `gptel-curl--stream-insert-response' - `gptel-curl--cleanup-stream': rename to `gptel-curl--stream-cleanup' - `gptel-curl--filter': rename to `gptel-curl--stream-filter'
This commit is contained in:
parent
ba133267ec
commit
a43f5ac5fa
2 changed files with 17 additions and 13 deletions
|
@ -83,22 +83,22 @@ the response is inserted into the current buffer after point."
|
||||||
(setf (alist-get process gptel-curl--process-alist)
|
(setf (alist-get process gptel-curl--process-alist)
|
||||||
(nconc (list :token token
|
(nconc (list :token token
|
||||||
:callback (or callback
|
:callback (or callback
|
||||||
(if gptel-playback
|
(if gptel-stream
|
||||||
#'gptel--insert-response-stream
|
#'gptel-curl--stream-insert-response
|
||||||
#'gptel--insert-response))
|
#'gptel--insert-response))
|
||||||
:transformer (when (or (eq gptel-default-mode 'org-mode)
|
:transformer (when (or (eq gptel-default-mode 'org-mode)
|
||||||
(eq (buffer-local-value
|
(eq (buffer-local-value
|
||||||
'major-mode
|
'major-mode
|
||||||
(plist-get info :gptel-buffer))
|
(plist-get info :gptel-buffer))
|
||||||
'org-mode))
|
'org-mode))
|
||||||
(gptel--convert-playback-markdown->org)))
|
(gptel--stream-convert-markdown->org)))
|
||||||
info))
|
info))
|
||||||
(if gptel-playback
|
(if gptel-stream
|
||||||
(progn (set-process-sentinel process #'gptel-curl--cleanup-stream)
|
(progn (set-process-sentinel process #'gptel-curl--stream-cleanup)
|
||||||
(set-process-filter process #'gptel-curl--filter))
|
(set-process-filter process #'gptel-curl--stream-filter))
|
||||||
(set-process-sentinel process #'gptel-curl--sentinel)))))
|
(set-process-sentinel process #'gptel-curl--sentinel)))))
|
||||||
|
|
||||||
(defun gptel-curl--cleanup-stream (process status)
|
(defun gptel-curl--stream-cleanup (process status)
|
||||||
"Process sentinel for GPTel curl requests.
|
"Process sentinel for GPTel curl requests.
|
||||||
|
|
||||||
PROCESS and STATUS are process parameters."
|
PROCESS and STATUS are process parameters."
|
||||||
|
@ -152,7 +152,7 @@ See `gptel--url-get-response' for details."
|
||||||
(gptel--update-header-line
|
(gptel--update-header-line
|
||||||
(format " Response Error: %s" status-str) 'error))))
|
(format " Response Error: %s" status-str) 'error))))
|
||||||
|
|
||||||
(defun gptel-curl--filter (process output)
|
(defun gptel-curl--stream-filter (process output)
|
||||||
(let* ((content-strs)
|
(let* ((content-strs)
|
||||||
(proc-info (alist-get process gptel-curl--process-alist)))
|
(proc-info (alist-get process gptel-curl--process-alist)))
|
||||||
(with-current-buffer (process-buffer process)
|
(with-current-buffer (process-buffer process)
|
||||||
|
@ -182,7 +182,7 @@ See `gptel--url-get-response' for details."
|
||||||
(http-status (plist-get proc-info :http-status)))
|
(http-status (plist-get proc-info :http-status)))
|
||||||
;; Find data chunk(s) and run callback
|
;; Find data chunk(s) and run callback
|
||||||
(funcall (or (plist-get proc-info :callback)
|
(funcall (or (plist-get proc-info :callback)
|
||||||
#'gptel--insert-response-stream)
|
#'gptel-curl--stream-insert-response)
|
||||||
(if (equal http-status "200")
|
(if (equal http-status "200")
|
||||||
(let* ((json-object-type 'plist)
|
(let* ((json-object-type 'plist)
|
||||||
(response) (content-str))
|
(response) (content-str))
|
||||||
|
|
12
gptel.el
12
gptel.el
|
@ -76,14 +76,18 @@ key (more secure)."
|
||||||
(string :tag "API key")
|
(string :tag "API key")
|
||||||
(function :tag "Function that returns the API key")))
|
(function :tag "Function that returns the API key")))
|
||||||
|
|
||||||
(defcustom gptel-playback nil
|
(defcustom gptel-stream nil
|
||||||
"Whether responses from ChatGPT be played back in chunks.
|
"Whether responses from ChatGPT be played back as they are received.
|
||||||
|
|
||||||
When set to nil, it is inserted all at once.
|
This option is ignored unless Curl is in use (see `gptel-use-curl').
|
||||||
|
|
||||||
|
When set to nil, Emacs waits for the full response and inserts it
|
||||||
|
all at once. This wait is asynchronous.
|
||||||
|
|
||||||
'tis a bit silly."
|
'tis a bit silly."
|
||||||
:group 'gptel
|
:group 'gptel
|
||||||
:type 'boolean)
|
:type 'boolean)
|
||||||
|
(make-obsolete-variable 'gptel-playback 'gptel-stream "0.3.0")
|
||||||
|
|
||||||
(defcustom gptel-use-curl (and (executable-find "curl") t)
|
(defcustom gptel-use-curl (and (executable-find "curl") t)
|
||||||
"Whether gptel should prefer Curl when available."
|
"Whether gptel should prefer Curl when available."
|
||||||
|
@ -556,7 +560,7 @@ elements."
|
||||||
(insert "/")))))))
|
(insert "/")))))))
|
||||||
(buffer-string)))
|
(buffer-string)))
|
||||||
|
|
||||||
(defun gptel--convert-playback-markdown->org ()
|
(defun gptel--stream-convert-markdown->org ()
|
||||||
"Return a Markdown to Org converter.
|
"Return a Markdown to Org converter.
|
||||||
|
|
||||||
This function parses a stream of Markdown text to Org
|
This function parses a stream of Markdown text to Org
|
||||||
|
|
Loading…
Add table
Reference in a new issue