gptel, gptel-curl: Address checkdoc warnings
* gptel.el (gptel--url-parse-response, gptel-max-tokens, gptel-use-header-line): Address checkdoc warnings. * gptel-curl.el (gptel-curl--parse-response, gptel-abort): Address checkdoc warnings. * gptel-gemini (gptel-make-gemini): Address checkdoc warnings.
This commit is contained in:
parent
7271d0e408
commit
4d01dddf7d
3 changed files with 35 additions and 34 deletions
|
@ -92,7 +92,7 @@ INFO is a plist with the following keys:
|
||||||
- :buffer (the gptel buffer)
|
- :buffer (the gptel buffer)
|
||||||
- :position (marker at which to insert the response).
|
- :position (marker at which to insert the response).
|
||||||
|
|
||||||
Call CALLBACK with the response and INFO afterwards. If omitted
|
Call CALLBACK with the response and INFO afterwards. If omitted
|
||||||
the response is inserted into the current buffer after point."
|
the response is inserted into the current buffer after point."
|
||||||
(let* ((token (md5 (format "%s%s%s%s"
|
(let* ((token (md5 (format "%s%s%s%s"
|
||||||
(random) (emacs-pid) (user-full-name)
|
(random) (emacs-pid) (user-full-name)
|
||||||
|
@ -139,7 +139,7 @@ the response is inserted into the current buffer after point."
|
||||||
(set-process-sentinel process #'gptel-curl--sentinel)))))
|
(set-process-sentinel process #'gptel-curl--sentinel)))))
|
||||||
|
|
||||||
(defun gptel-abort (buf)
|
(defun gptel-abort (buf)
|
||||||
"Stop any active gptel process associated with the current buffer."
|
"Stop any active gptel process associated with buffer BUF."
|
||||||
(interactive (list (current-buffer)))
|
(interactive (list (current-buffer)))
|
||||||
(unless gptel-use-curl
|
(unless gptel-use-curl
|
||||||
(user-error "Cannot stop a `url-retrieve' request!"))
|
(user-error "Cannot stop a `url-retrieve' request!"))
|
||||||
|
@ -295,9 +295,9 @@ See `gptel--url-get-response' for details."
|
||||||
(when-let ((http-msg (plist-get proc-info :status))
|
(when-let ((http-msg (plist-get proc-info :status))
|
||||||
(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
|
||||||
(when-let ((_ (equal http-status "200"))
|
(when-let (((equal http-status "200"))
|
||||||
(response (funcall (plist-get proc-info :parser) nil proc-info))
|
(response (funcall (plist-get proc-info :parser) nil proc-info))
|
||||||
(_ (not (equal response ""))))
|
((not (equal response ""))))
|
||||||
(funcall (or (plist-get proc-info :callback)
|
(funcall (or (plist-get proc-info :callback)
|
||||||
#'gptel-curl--stream-insert-response)
|
#'gptel-curl--stream-insert-response)
|
||||||
response proc-info))))))
|
response proc-info))))))
|
||||||
|
@ -337,8 +337,7 @@ PROCESS and _STATUS are process parameters."
|
||||||
(defun gptel-curl--parse-response (proc-info)
|
(defun gptel-curl--parse-response (proc-info)
|
||||||
"Parse the buffer BUF with curl's response.
|
"Parse the buffer BUF with curl's response.
|
||||||
|
|
||||||
TOKEN is used to disambiguate multiple requests in a single
|
PROC-INFO is a plist with contextual information."
|
||||||
buffer."
|
|
||||||
(let ((token (plist-get proc-info :token))
|
(let ((token (plist-get proc-info :token))
|
||||||
(parser (plist-get proc-info :parser)))
|
(parser (plist-get proc-info :parser)))
|
||||||
(goto-char (point-max))
|
(goto-char (point-max))
|
||||||
|
|
|
@ -115,7 +115,7 @@ HOST (optional) is the API host, defaults to
|
||||||
MODELS is a list of available model names. Currently only
|
MODELS is a list of available model names. Currently only
|
||||||
\"gemini-pro\" is available.
|
\"gemini-pro\" is available.
|
||||||
|
|
||||||
STREAM is a boolean to toggle streaming responses, defaults to
|
STREAM is a boolean to enable streaming responses, defaults to
|
||||||
false.
|
false.
|
||||||
|
|
||||||
PROTOCOL (optional) specifies the protocol, \"https\" by default.
|
PROTOCOL (optional) specifies the protocol, \"https\" by default.
|
||||||
|
|
56
gptel.el
56
gptel.el
|
@ -29,7 +29,8 @@
|
||||||
|
|
||||||
;; gptel is a simple Large Language Model chat client, with support for multiple models/backends.
|
;; gptel is a simple Large Language Model chat client, with support for multiple models/backends.
|
||||||
;;
|
;;
|
||||||
;; gptel supports ChatGPT, Azure, and local models using Ollama and GPT4All.
|
;; gptel supports ChatGPT, Azure, Gemini and local models using Ollama and
|
||||||
|
;; GPT4All.
|
||||||
;;
|
;;
|
||||||
;; Features:
|
;; Features:
|
||||||
;; - It’s async and fast, streams responses.
|
;; - It’s async and fast, streams responses.
|
||||||
|
@ -39,13 +40,13 @@
|
||||||
;; - Supports conversations and multiple independent sessions.
|
;; - Supports conversations and multiple independent sessions.
|
||||||
;; - Save chats as regular Markdown/Org/Text files and resume them later.
|
;; - Save chats as regular Markdown/Org/Text files and resume them later.
|
||||||
;; - You can go back and edit your previous prompts or LLM responses when
|
;; - You can go back and edit your previous prompts or LLM responses when
|
||||||
;; continuing a conversation. These will be fed back to the model.
|
;; continuing a conversation. These will be fed back to the model.
|
||||||
;;
|
;;
|
||||||
;; Requirements for ChatGPT, Azure or Gemini:
|
;; Requirements for ChatGPT, Azure or Gemini:
|
||||||
;;
|
;;
|
||||||
;; - You need an appropriate API key. Set the variable `gptel-api-key' to the
|
;; - You need an appropriate API key. Set the variable `gptel-api-key' to the
|
||||||
;; key or to a function of no arguments that returns the key. (It tries to use
|
;; key or to a function of no arguments that returns the key. (It tries to
|
||||||
;; `auth-source' by default)
|
;; use `auth-source' by default)
|
||||||
;;
|
;;
|
||||||
;; - For Azure: define a gptel-backend with `gptel-make-azure', which see.
|
;; - For Azure: define a gptel-backend with `gptel-make-azure', which see.
|
||||||
;; - For Gemini: define a gptel-backend with `gptel-make-gemini', which see.
|
;; - For Gemini: define a gptel-backend with `gptel-make-gemini', which see.
|
||||||
|
@ -58,9 +59,9 @@
|
||||||
;;
|
;;
|
||||||
;; Usage:
|
;; Usage:
|
||||||
;;
|
;;
|
||||||
;; gptel can be used in any buffer or in a dedicated chat buffer. The
|
;; gptel can be used in any buffer or in a dedicated chat buffer. The
|
||||||
;; interaction model is simple: Type in a query and the response will be
|
;; interaction model is simple: Type in a query and the response will be
|
||||||
;; inserted below. You can continue the conversation by typing below the
|
;; inserted below. You can continue the conversation by typing below the
|
||||||
;; response.
|
;; response.
|
||||||
;;
|
;;
|
||||||
;; To use this in a dedicated buffer:
|
;; To use this in a dedicated buffer:
|
||||||
|
@ -68,12 +69,12 @@
|
||||||
;; - C-u M-x gptel: Start another session or multiple independent ChatGPT sessions
|
;; - C-u M-x gptel: Start another session or multiple independent ChatGPT sessions
|
||||||
;;
|
;;
|
||||||
;; - In the chat session: Press `C-c RET' (`gptel-send') to send your prompt.
|
;; - In the chat session: Press `C-c RET' (`gptel-send') to send your prompt.
|
||||||
;; Use a prefix argument (`C-u C-c RET') to access a menu. In this menu you
|
;; Use a prefix argument (`C-u C-c RET') to access a menu. In this menu you
|
||||||
;; can set chat parameters like the system directives, active backend or
|
;; can set chat parameters like the system directives, active backend or
|
||||||
;; model, or choose to redirect the input or output elsewhere (such as to the
|
;; model, or choose to redirect the input or output elsewhere (such as to the
|
||||||
;; kill ring).
|
;; kill ring).
|
||||||
;;
|
;;
|
||||||
;; - You can save this buffer to a file. When opening this file, turning on
|
;; - You can save this buffer to a file. When opening this file, turning on
|
||||||
;; `gptel-mode' will allow resuming the conversation.
|
;; `gptel-mode' will allow resuming the conversation.
|
||||||
;;
|
;;
|
||||||
;; To use this in any buffer:
|
;; To use this in any buffer:
|
||||||
|
@ -157,7 +158,7 @@ key (more secure) for the active backend."
|
||||||
This option is ignored unless Curl is in use (see `gptel-use-curl').
|
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
|
When set to nil, Emacs waits for the full response and inserts it
|
||||||
all at once. This wait is asynchronous.
|
all at once. This wait is asynchronous.
|
||||||
|
|
||||||
\='tis a bit silly."
|
\='tis a bit silly."
|
||||||
:group 'gptel
|
:group 'gptel
|
||||||
|
@ -173,9 +174,9 @@ all at once. This wait is asynchronous.
|
||||||
"Size threshold for using file input with Curl.
|
"Size threshold for using file input with Curl.
|
||||||
|
|
||||||
Specifies the size threshold for when to use a temporary file to pass data to
|
Specifies the size threshold for when to use a temporary file to pass data to
|
||||||
Curl in GPTel queries. If the size of the data to be sent exceeds this
|
Curl in GPTel queries. If the size of the data to be sent exceeds this
|
||||||
threshold, the data is written to a temporary file and passed to Curl using the
|
threshold, the data is written to a temporary file and passed to Curl using the
|
||||||
`--data-binary' option with a file reference. Otherwise, the data is passed
|
`--data-binary' option with a file reference. Otherwise, the data is passed
|
||||||
directly as a command-line argument.
|
directly as a command-line argument.
|
||||||
|
|
||||||
The value is an integer representing the number of bytes.
|
The value is an integer representing the number of bytes.
|
||||||
|
@ -197,8 +198,8 @@ such as filling paragraphs, adding annotations or recording
|
||||||
information in the response like links.
|
information in the response like links.
|
||||||
|
|
||||||
Each function in this hook receives two arguments, the response
|
Each function in this hook receives two arguments, the response
|
||||||
string to transform and the ChatGPT interaction buffer. It should
|
string to transform and the ChatGPT interaction buffer. It
|
||||||
return the transformed string."
|
should return the transformed string."
|
||||||
:group 'gptel
|
:group 'gptel
|
||||||
:type 'hook)
|
:type 'hook)
|
||||||
|
|
||||||
|
@ -206,7 +207,7 @@ return the transformed string."
|
||||||
"Hook run before inserting ChatGPT's response into the current buffer.
|
"Hook run before inserting ChatGPT's response into the current buffer.
|
||||||
|
|
||||||
This hook is called in the buffer from which the prompt was sent
|
This hook is called in the buffer from which the prompt was sent
|
||||||
to ChatGPT. Note: this hook only runs if the request succeeds."
|
to ChatGPT. Note: this hook only runs if the request succeeds."
|
||||||
:group 'gptel
|
:group 'gptel
|
||||||
:type 'hook)
|
:type 'hook)
|
||||||
|
|
||||||
|
@ -214,7 +215,7 @@ to ChatGPT. Note: this hook only runs if the request succeeds."
|
||||||
"Hook run after inserting the LLM response into the current buffer.
|
"Hook run after inserting the LLM response into the current buffer.
|
||||||
|
|
||||||
This hook is called in the buffer from which the prompt was sent
|
This hook is called in the buffer from which the prompt was sent
|
||||||
to the LLM, and after the full response has been inserted. Note:
|
to the LLM, and after the full response has been inserted. Note:
|
||||||
this hook runs even if the request fails."
|
this hook runs even if the request fails."
|
||||||
:group 'gptel
|
:group 'gptel
|
||||||
:type 'hook)
|
:type 'hook)
|
||||||
|
@ -241,7 +242,7 @@ to the LLM, and after a text insertion."
|
||||||
'text-mode)
|
'text-mode)
|
||||||
"The default major mode for dedicated chat buffers.
|
"The default major mode for dedicated chat buffers.
|
||||||
|
|
||||||
If `markdown-mode' is available, it is used. Otherwise gptel
|
If `markdown-mode' is available, it is used. Otherwise gptel
|
||||||
defaults to `text-mode'."
|
defaults to `text-mode'."
|
||||||
:group 'gptel
|
:group 'gptel
|
||||||
:type 'symbol)
|
:type 'symbol)
|
||||||
|
@ -276,7 +277,8 @@ is only inserted in dedicated gptel buffers before the AI's response."
|
||||||
:type '(alist :key-type symbol :value-type string))
|
:type '(alist :key-type symbol :value-type string))
|
||||||
|
|
||||||
(defcustom gptel-use-header-line t
|
(defcustom gptel-use-header-line t
|
||||||
"Whether gptel-mode should use the header-line for status information.
|
"Whether `gptel-mode' should use header-line for status
|
||||||
|
information.
|
||||||
|
|
||||||
When set to nil, use the mode line for (minimal) status
|
When set to nil, use the mode line for (minimal) status
|
||||||
information and the echo area for messages."
|
information and the echo area for messages."
|
||||||
|
@ -332,7 +334,7 @@ These are system instructions sent at the beginning of each
|
||||||
request to ChatGPT.
|
request to ChatGPT.
|
||||||
|
|
||||||
Each entry in this alist maps a symbol naming the directive to
|
Each entry in this alist maps a symbol naming the directive to
|
||||||
the string that is sent. To set the directive for a chat session
|
the string that is sent. To set the directive for a chat session
|
||||||
interactively call `gptel-send' with a prefix argument."
|
interactively call `gptel-send' with a prefix argument."
|
||||||
:group 'gptel
|
:group 'gptel
|
||||||
:safe #'gptel--always
|
:safe #'gptel--always
|
||||||
|
@ -344,7 +346,7 @@ interactively call `gptel-send' with a prefix argument."
|
||||||
(defcustom gptel-max-tokens nil
|
(defcustom gptel-max-tokens nil
|
||||||
"Max tokens per response.
|
"Max tokens per response.
|
||||||
|
|
||||||
This is roughly the number of words in the response. 100-300 is a
|
This is roughly the number of words in the response. 100-300 is a
|
||||||
reasonable range for short answers, 400 or more for longer
|
reasonable range for short answers, 400 or more for longer
|
||||||
responses.
|
responses.
|
||||||
|
|
||||||
|
@ -679,7 +681,7 @@ file."
|
||||||
(system gptel--system-message))
|
(system gptel--system-message))
|
||||||
"Request a response from the `gptel-backend' for PROMPT.
|
"Request a response from the `gptel-backend' for PROMPT.
|
||||||
|
|
||||||
Note: This function is not fully self-contained. Consider
|
Note: This function is not fully self-contained. Consider
|
||||||
let-binding the parameters `gptel-backend' and `gptel-model'
|
let-binding the parameters `gptel-backend' and `gptel-model'
|
||||||
around calls to it as required.
|
around calls to it as required.
|
||||||
|
|
||||||
|
@ -696,7 +698,7 @@ Keyword arguments:
|
||||||
CALLBACK, if supplied, is a function of two arguments, called
|
CALLBACK, if supplied, is a function of two arguments, called
|
||||||
with the RESPONSE (a string) and INFO (a plist):
|
with the RESPONSE (a string) and INFO (a plist):
|
||||||
|
|
||||||
(callback RESPONSE INFO)
|
(callback RESPONSE INFO)
|
||||||
|
|
||||||
RESPONSE is nil if there was no response or an error.
|
RESPONSE is nil if there was no response or an error.
|
||||||
|
|
||||||
|
@ -709,7 +711,7 @@ The INFO plist has (at least) the following keys:
|
||||||
Example of a callback that messages the user with the response
|
Example of a callback that messages the user with the response
|
||||||
and info:
|
and info:
|
||||||
|
|
||||||
(lambda (response info)
|
(lambda (response info)
|
||||||
(if response
|
(if response
|
||||||
(let ((posn (marker-position (plist-get info :position)))
|
(let ((posn (marker-position (plist-get info :position)))
|
||||||
(buf (buffer-name (plist-get info :buffer))))
|
(buf (buffer-name (plist-get info :buffer))))
|
||||||
|
@ -720,7 +722,7 @@ and info:
|
||||||
|
|
||||||
Or, for just the response:
|
Or, for just the response:
|
||||||
|
|
||||||
(lambda (response _)
|
(lambda (response _)
|
||||||
;; Do something with response
|
;; Do something with response
|
||||||
(message (rot13-string response)))
|
(message (rot13-string response)))
|
||||||
|
|
||||||
|
@ -969,7 +971,7 @@ INFO is a plist with the following keys:
|
||||||
- :buffer (the gptel buffer)
|
- :buffer (the gptel buffer)
|
||||||
- :position (marker at which to insert the response).
|
- :position (marker at which to insert the response).
|
||||||
|
|
||||||
Call CALLBACK with the response and INFO afterwards. If omitted
|
Call CALLBACK with the response and INFO afterwards. If omitted
|
||||||
the response is inserted into the current buffer after point."
|
the response is inserted into the current buffer after point."
|
||||||
(let* ((inhibit-message t)
|
(let* ((inhibit-message t)
|
||||||
(message-log-max nil)
|
(message-log-max nil)
|
||||||
|
@ -1008,7 +1010,7 @@ PROC-INFO is a plist with process information and other context.
|
||||||
See `gptel-curl--get-response' for its contents.")
|
See `gptel-curl--get-response' for its contents.")
|
||||||
|
|
||||||
(defun gptel--url-parse-response (backend response-buffer)
|
(defun gptel--url-parse-response (backend response-buffer)
|
||||||
"Parse response in RESPONSE-BUFFER."
|
"Parse response from BACKEND in RESPONSE-BUFFER."
|
||||||
(when (buffer-live-p response-buffer)
|
(when (buffer-live-p response-buffer)
|
||||||
(when gptel--debug
|
(when gptel--debug
|
||||||
(with-current-buffer response-buffer
|
(with-current-buffer response-buffer
|
||||||
|
@ -1056,7 +1058,7 @@ With a prefix arg, query for a (new) session name.
|
||||||
|
|
||||||
Ask for API-KEY if `gptel-api-key' is unset.
|
Ask for API-KEY if `gptel-api-key' is unset.
|
||||||
|
|
||||||
If region is active, use it as the INITIAL prompt. Returns the
|
If region is active, use it as the INITIAL prompt. Returns the
|
||||||
buffer created or switched to."
|
buffer created or switched to."
|
||||||
(interactive (list (if current-prefix-arg
|
(interactive (list (if current-prefix-arg
|
||||||
(read-string "Session name: " (generate-new-buffer-name gptel-default-session))
|
(read-string "Session name: " (generate-new-buffer-name gptel-default-session))
|
||||||
|
|
Loading…
Add table
Reference in a new issue