branch: elpa/gptel commit 08abac19bed17a7780d6bdab3d5c00ac8339e231 Author: Karthik Chikmagalur <karthikchikmaga...@gmail.com> Commit: Karthik Chikmagalur <karthikchikmaga...@gmail.com>
gptel: Try to ensure tool spec argument preprocessing (#794) * gptel.el (gptel--preprocess-tool-args): When native-compiled, `gptel--make-tool' is running/not running the advice `gptel--preprocess-tool-args', depending on the evaluation environment. This remains broken, but this commit is an attempt to figure out why. Explicitly return the spec from the preprocessing advice. --- gptel.el | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/gptel.el b/gptel.el index 39256c4442..3fb4bad0df 100644 --- a/gptel.el +++ b/gptel.el @@ -1556,27 +1556,26 @@ feed the LLM the results. You can add tools via "Convert symbol :type values in tool SPEC to strings destructively." ;; NOTE: Do not use `sequencep' here, as that covers strings too and breaks ;; things. - (cond ((not (or (listp spec) (vectorp spec))) spec) - ((vectorp spec) - (cl-loop for element across spec - for idx upfrom 0 - do (aset spec idx (gptel--preprocess-tool-args element))) - spec) - ((keywordp (car spec)) - (let ((tail spec)) - (while tail - (when (and (eq (car tail) :type) (symbolp (cadr tail))) - (setcar (cdr tail) (symbol-name (cadr tail)))) - ;; TODO: Handle :enum ("provided" "as" "list") here, convert to - ;; :enum ["provided" "as" "array"] - (when (or (listp (cadr tail)) (vectorp (cadr tail))) - (gptel--preprocess-tool-args (cadr tail))) - (setq tail (cddr tail))) - spec)) - ((listp spec) (dolist (element spec) - (when (listp element) - (gptel--preprocess-tool-args element))) - spec))) + (when (or (listp spec) (vectorp spec)) + (cond + ((vectorp spec) + (cl-loop for element across spec + for idx upfrom 0 + do (aset spec idx (gptel--preprocess-tool-args element)))) + ((keywordp (car spec)) + (let ((tail spec)) + (while tail + (when (and (eq (car tail) :type) (symbolp (cadr tail))) + (setcar (cdr tail) (symbol-name (cadr tail)))) + ;; TODO: Handle :enum ("provided" "as" "list") here, convert to + ;; :enum ["provided" "as" "array"] + (when (or (listp (cadr tail)) (vectorp (cadr tail))) + (gptel--preprocess-tool-args (cadr tail))) + (setq tail (cddr tail))))) + ((listp spec) (dolist (element spec) + (when (listp element) + (gptel--preprocess-tool-args element)))))) + spec) (defvar gptel--known-tools nil "Alist of gptel tools arranged by category.