fix(gptel-magit): handle reasoning cells in callbacks
This commit is contained in:
@@ -101,7 +101,12 @@
|
||||
)
|
||||
|
||||
(add-hook 'gptel-post-response-functions 'gptel-end-of-response)
|
||||
(setopt gptel-include-reasoning nil) ;; Mantener hasta resolver: https://github.com/ragnard/gptel-magit/issues/8
|
||||
;; El "thinking" de los modelos se muestra en los buffers gptel.
|
||||
;; `ignore' (valor por defecto de gptel) lo muestra pero NO lo reenvía
|
||||
;; al modelo en turnos posteriores (recomendado: evita llenar el
|
||||
;; contexto, ver NEWS de gptel). Usar `t' si además se quiere
|
||||
;; reenviarlo y `nil' para deshabilitarlo (útil para respuestas mas rápidas).
|
||||
(setopt gptel-include-reasoning 'ignore)
|
||||
|
||||
(defun gptel-switch+model ()
|
||||
"Switch to gptel backend and model in a single completion prompt."
|
||||
@@ -142,7 +147,41 @@
|
||||
|
||||
(use-package gptel-magit
|
||||
:ensure t
|
||||
:hook (magit-mode . gptel-magit-install))
|
||||
:hook (magit-mode . gptel-magit-install)
|
||||
:config
|
||||
;; gptel-magit no sabe manejar el contenido de "reasoning": gptel entrega
|
||||
;; el thinking al callback como (reasoning . TEXTO) y gptel-magit lo
|
||||
;; inserta como si fuera la respuesta final, fallando con
|
||||
;; Wrong type argument: char-or-string-p, (reasoning . "...")
|
||||
;; (https://github.com/ragnard/gptel-magit/issues/8). Esto ocurre
|
||||
;; aunque `gptel-include-reasoning' sea nil, porque gptel entrega las
|
||||
;; celdas (reasoning . ...) al callback de forma incondicional (solo
|
||||
;; controla si se insertan en el buffer gptel y si se reenvían).
|
||||
;; En vez de deshabilitar el thinking globalmente, sanitizamos la
|
||||
;; respuesta en el callback: se descartan las celdas de reasoning y solo
|
||||
;; se deja pasar la respuesta final (string). Así el thinking sigue
|
||||
;; activo en las sesiones gptel normales.
|
||||
(defun kj-gptel-magit--string-response-callback (callback)
|
||||
"Return a callback that forwards only string responses to CALLBACK.
|
||||
Descarta las celdas (reasoning . TEXTO) con las que gptel entrega el
|
||||
contenido de thinking al callback (ver `gptel-request')."
|
||||
(lambda (response &rest args)
|
||||
(when (stringp response)
|
||||
(apply callback response args))))
|
||||
|
||||
(defun kj-gptel-magit--sanitize-callback (orig-fn &rest args)
|
||||
"Around advice for `gptel-magit--request'.
|
||||
Envuelve el argumento :callback de ARGS para que las respuestas con
|
||||
contenido de reasoning no rompan gptel-magit."
|
||||
(let ((pos (cl-position :callback args)))
|
||||
(when (and pos (functionp (nth (1+ pos) args)))
|
||||
(setf (nth (1+ pos) args)
|
||||
(kj-gptel-magit--string-response-callback
|
||||
(nth (1+ pos) args)))))
|
||||
(apply orig-fn args))
|
||||
|
||||
(advice-add 'gptel-magit--request :around
|
||||
#'kj-gptel-magit--sanitize-callback))
|
||||
|
||||
(use-package gptel-autocomplete
|
||||
:defer nil
|
||||
|
||||
Reference in New Issue
Block a user