Function: gptel--realize-query
gptel--realize-query is a natively compiled function defined in
gptel-request.el.
Signature
(gptel--realize-query FSM)
Documentation
Realize the query payload for FSM from its prompt buffer.
Initiate the request when done.
Source Code
;; Defined in /nix/store/q3r7g81pvghw7a523kjk2k2zih3pfk8z-emacs-packages-deps/share/emacs/site-lisp/elpa/gptel-20261002.545/gptel-request.el
(defun gptel--realize-query (fsm)
"Realize the query payload for FSM from its prompt buffer.
Initiate the request when done."
(let ((info (gptel-fsm-info fsm)))
(with-current-buffer (plist-get info :data)
(let* ((directive (gptel--parse-directive gptel-system-prompt 'raw))
;; DIRECTIVE contains both the system message and the template prompts
(gptel-system-prompt
(unless (gptel--model-capable-p 'nosystem) (car directive)))
;; TODO(tool) Limit tool use to capable models after documenting :capabilities
;; (gptel-use-tools (and (gptel--model-capable-p 'tool-use) gptel-use-tools))
(stream (and (plist-get info :stream) gptel-use-curl gptel-stream
;; Check model-specific request-params for streaming preference
(let* ((model-params (gptel--model-request-params gptel-model))
(stream-spec (plist-get model-params :stream)))
;; If not present, there is no model-specific preference
(or (not (memq :stream model-params))
;; If present, it must not be :json-false or nil
(and stream-spec (not (eq stream-spec :json-false)))))
;; Check backend-specific streaming settings
(gptel-backend-stream gptel-backend)))
(gptel-stream stream)
(full-prompt))
(when (cdr directive) ; prompt constructed from directive/template
(save-excursion (goto-char (point-min))
(gptel--parse-list-and-insert (cdr directive))))
(goto-char (point-max))
(setq full-prompt (gptel--parse-buffer ;prompt from buffer or explicitly supplied
gptel-backend (and gptel--num-messages-to-send
(* 2 gptel--num-messages-to-send))))
;; Inject media chunks into the first user prompt if required. Media
;; chunks are always included with the first user message,
;; irrespective of the preference in `gptel-use-context'. This is
;; because media cannot be included (in general) with system messages.
;; TODO(augment): Find a way to do this in the prompt-buffer?
(when (and gptel-context gptel-use-context (gptel--model-capable-p 'media))
(gptel--inject-media gptel-backend full-prompt))
(unless stream (cl-remf info :stream))
(plist-put info :backend gptel-backend)
(plist-put info :model gptel-model)
(when gptel-include-reasoning ;Required for next-request-only scope
(plist-put info :include-reasoning gptel-include-reasoning))
(when (and gptel-use-tools gptel-tools)
(plist-put info :tools gptel-tools))
(plist-put info :data
(gptel--request-data gptel-backend full-prompt)))
(kill-buffer (current-buffer)))
;; INIT -> WAIT
(unless (plist-get info :dry-run) (gptel--fsm-transition fsm))
fsm))