Function: gptel--parse-list-and-insert

gptel--parse-list-and-insert is a natively compiled function defined in gptel-request.el.

Signature

(gptel--parse-list-and-insert PROMPTS)

Documentation

Insert PROMPTS, a list of messages into the current buffer.

Propertize the insertions in a format gptel can parse into a conversation.

PROMPTS is typically the input to gptel-request, either a list of strings representing a conversation with alternate prompt/response turns, or a list of lists with explicit roles (prompt/response/tool).

See gptel-request for the former. Support for the latter format is experimental.

Source Code

;; Defined in /nix/store/q3r7g81pvghw7a523kjk2k2zih3pfk8z-emacs-packages-deps/share/emacs/site-lisp/elpa/gptel-20261002.545/gptel-request.el
(defun gptel--parse-list-and-insert (prompts)
  "Insert PROMPTS, a list of messages into the current buffer.

Propertize the insertions in a format gptel can parse into a
conversation.

PROMPTS is typically the input to `gptel-request', either a list of strings
representing a conversation with alternate prompt/response turns, or a list of
lists with explicit roles (prompt/response/tool).

See `gptel-request' for the former.  Support for the latter format is
experimental."
  (if (stringp (car prompts))           ; Simple format, list of strings
      (cl-loop for text in prompts
               for response = nil then (not response)
               when text
               if response
               do (insert gptel-response-separator
                          (propertize text 'gptel 'response)
                          gptel-response-separator)
               else do (insert text))
    (dolist (entry prompts)             ; Advanced format, list of lists
      (pcase entry
        (`(prompt . ,msg) (insert (or (car-safe msg) msg)))
        (`(response . ,msg)
         (insert gptel-response-separator
                 (propertize (or (car-safe msg) msg) 'gptel 'response)))
        (`(tool . ,call)
         (insert gptel-response-separator
                 (propertize
                  (concat
                   (prin1-to-string `( :name ,(plist-get call :name)
                                       :args ,(plist-get call :args)))
                   "\n\n" (plist-get call :result))
                  'gptel `(tool . ,(plist-get call :id)))))))))