Function: gptel-curl--get-config

gptel-curl--get-config is a natively compiled function defined in gptel-request.el.

Signature

(gptel-curl--get-config INFO UUID)

Documentation

Produce config text for calling Curl.

INFO contains the request data, UUID is a unique identifier.

Source Code

;; Defined in /nix/store/q3r7g81pvghw7a523kjk2k2zih3pfk8z-emacs-packages-deps/share/emacs/site-lisp/elpa/gptel-20261002.545/gptel-request.el
(defun gptel-curl--get-config (info uuid)
  "Produce config text for calling Curl.

INFO contains the request data, UUID is a unique identifier."
  (let* (;; We have to let-bind the following three since their dynamic
         ;; values are used for key lookup and url resolution
         (gptel-backend (plist-get info :backend))
         (gptel-model (plist-get info :model))
         (gptel-stream (plist-get info :stream))
         (url (let ((backend-url (gptel-backend-url gptel-backend)))
                (gptel--maybe-funcall backend-url info)))
         (data (plist-get info :data))
         (data-json (encode-coding-string (gptel--json-encode data) 'utf-8-unix t))
         (headers
          (append '(("Content-Type" . "application/json"))
                  (when-let* ((header (gptel-backend-header gptel-backend)))
                    (gptel--maybe-funcall header info))))
         (items
          (nconc
           (cl-loop for (key . val) in headers
                    collect (cons "header" (format "%s: %s" key val)))
           (when (not (string-empty-p gptel-proxy))
             (list (cons "proxy" gptel-proxy) "proxy-negotiate" (cons "proxy-user" ":")))
           (list
            (cons "url" url)
            (cons "write-out" (format "(%s . %%{size_header})" uuid))
            (cons "data-binary" '@-))))
         (config (cl-loop for item in items
                          concat (cl-etypecase item
                                   (string (format "%s" item))
                                   (cons (format "%s = %S" (car item) (cdr item))))
                          concat "\n")))
    (when gptel-log-level
      (when (eq gptel-log-level 'debug)
        (gptel--log config "request config"))
      (gptel--log data-json "request body"))
    (concat config "\n" data-json)))