Function: gptel--parse-tools
gptel--parse-tools is a byte-compiled function defined in
gptel-request.el.
Signature
(gptel--parse-tools BACKEND TOOLS)
Documentation
Parse TOOLS and return a list of prompts.
TOOLS is a list of gptel-tool structs, which see.
_BACKEND is the LLM backend in use. This is the default
implementation, used by OpenAI-compatible APIs and Ollama.
Implementations
(gptel--parse-tools BACKEND TOOLS) in `gptel-request.el'.
Undocumented
Source Code
;; Defined in /nix/store/q3r7g81pvghw7a523kjk2k2zih3pfk8z-emacs-packages-deps/share/emacs/site-lisp/elpa/gptel-20261002.545/gptel-request.el
(cl-defgeneric gptel--parse-tools (_backend tools)
"Parse TOOLS and return a list of prompts.
TOOLS is a list of `gptel-tool' structs, which see.
_BACKEND is the LLM backend in use. This is the default
implementation, used by OpenAI-compatible APIs and Ollama."
(vconcat
(mapcar
(lambda (tool)
(list
:type "function"
:function
(append
(list
:name (gptel-tool-name tool)
:description (gptel-tool-description tool))
(if (gptel-tool-args tool)
(list
:parameters
(list :type "object"
;; gptel's tool args spec is close to the JSON schema, except
;; that we use (:name "argname" ...)
;; instead of (:argname (...)), and
;; (:optional t) for each arg instead of (:required [...])
;; for all args at once. Handle this difference by
;; modifying a copy of the gptel tool arg spec.
:properties
(cl-loop
for arg in (gptel-tool-args tool)
for argspec = (copy-sequence arg)
for name = (plist-get arg :name) ;handled differently
for newname = (or (and (keywordp name) name)
(make-symbol (concat ":" name)))
do ;ARGSPEC is ARG without unrecognized keys
(cl-remf argspec :name)
(cl-remf argspec :optional)
if (equal (plist-get arg :type) "object")
do (unless (plist-member argspec :required)
(plist-put argspec :required []))
(plist-put argspec :additionalProperties :json-false)
append (list newname argspec))
:required
(vconcat
(delq nil (mapcar
(lambda (arg) (and (not (plist-get arg :optional))
(plist-get arg :name)))
(gptel-tool-args tool))))
:additionalProperties :json-false))
(list :parameters (list :type "object" :properties nil))))))
(ensure-list tools))))