Function: gptel--preset-mismatch-value

gptel--preset-mismatch-value is a natively compiled function defined in gptel.el.

Signature

(gptel--preset-mismatch-value PRESET-SPEC KEY VAL)

Documentation

Determine if the value of KEY in PRESET-SPEC matches VAL.

This is an imperfect check for whether the value corresponding to KEY (a keyword) in PRESET-SPEC (a plist) matches VAL. This is required primarily to identify which gptel variable values have changed since PRESET-SPEC was applied, which is relevant when writing gptel metadata to a chat file.

See also gptel--preset-mismatch-p.

Source Code

;; Defined in /nix/store/q3r7g81pvghw7a523kjk2k2zih3pfk8z-emacs-packages-deps/share/emacs/site-lisp/elpa/gptel-20261002.545/gptel.el
(defun gptel--preset-mismatch-value (preset-spec key val)
  "Determine if the value of KEY in PRESET-SPEC matches VAL.

This is an imperfect check for whether the value corresponding to KEY (a
keyword) in PRESET-SPEC (a plist) matches VAL.  This is required
primarily to identify which gptel variable values have changed since
PRESET-SPEC was applied, which is relevant when writing gptel metadata
to a chat file.

See also `gptel--preset-mismatch-p'."
  ;; In all cases, assume a mismatch if the preset's value for KEY is a
  ;; modify-list spec, such as (:append ...)
  ;; Mismatches may not even be well-defined/determinable in these cases.
  (or (not preset-spec)
      (pcase key
        ;; special cases
        ((or :system :system-message)
         (let ((system (plist-get preset-spec :system)))
           (or (and (stringp system) (not (equal system val)))
               (functionp system)
               (and (consp system) (keywordp (car system)))
               (and (consp system)
                    (not (equal (car-safe (gptel--parse-directive system))
                                val))))))
        (:backend
         (let ((backend (plist-get preset-spec :backend)))
           (or (and (consp backend) (keywordp (car-safe backend)))
               (not (equal (or (and (gptel-backend-p val) (gptel-backend-name val))
                               val)
                           (or (and (gptel-backend-p backend) (gptel-backend-name backend))
                               backend))))))
        ;; FIXME: We're assuming that val is a list of tool names, not tools
        (:tools
         (and-let* ((preset-tools (plist-get preset-spec :tools)))
           (or (keywordp (car-safe preset-tools))
               (cl-loop
                for tool in preset-tools
                for tool-name =
                (or (and (stringp tool) tool)
                    (ignore-errors (gptel-tool-name
                                    (gptel-get-tool tool))))
                if (not (member tool-name uniq-tool-names))
                collect tool-name into uniq-tool-names
                finally return
                (not (equal (sort uniq-tool-names #'string-lessp)
                            (sort (copy-sequence (ensure-list val)) #'string-lessp)))))))
        ;; Generic case
        (_ (let ((field-val (plist-get preset-spec key)))
             (or (and (consp field-val) (keywordp (car field-val)))
                 (not (equal field-val val))))))))